File tree Expand file tree Collapse file tree 9 files changed +35
-11
lines changed Expand file tree Collapse file tree 9 files changed +35
-11
lines changed Original file line number Diff line number Diff line change @@ -195,7 +195,7 @@ void checkStoreNotSymlink()
195
195
}
196
196
197
197
198
- LocalStore::LocalStore ()
198
+ LocalStore::LocalStore (bool reserveSpace )
199
199
{
200
200
substitutablePathsLoaded = false ;
201
201
@@ -221,6 +221,24 @@ LocalStore::LocalStore()
221
221
222
222
checkStoreNotSymlink ();
223
223
224
+ /* We can't open a SQLite database if the disk is full. Since
225
+ this prevents the garbage collector from running when it's most
226
+ needed, we reserve some dummy space that we can free just
227
+ before doing a garbage collection. */
228
+ try {
229
+ Path reservedPath = nixDBPath + " /reserved" ;
230
+ if (reserveSpace) {
231
+ int reservedSize = queryIntSetting (" gc-reserved-space" , 1024 * 1024 );
232
+ struct stat st;
233
+ if (stat (reservedPath.c_str (), &st) == -1 ||
234
+ st.st_size != reservedSize)
235
+ writeFile (reservedPath, string (reservedSize, ' X' ));
236
+ }
237
+ else
238
+ deletePath (reservedPath);
239
+ } catch (SysError & e) { /* don't care about errors */
240
+ }
241
+
224
242
/* Acquire the big fat lock in shared mode to make sure that no
225
243
schema upgrade is in progress. */
226
244
try {
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ public:
91
91
92
92
/* Initialise the local store, upgrading the schema if
93
93
necessary. */
94
- LocalStore ();
94
+ LocalStore (bool reserveSpace = true );
95
95
96
96
~LocalStore ();
97
97
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ RemoteStore::RemoteStore()
43
43
}
44
44
45
45
46
- void RemoteStore::openConnection ()
46
+ void RemoteStore::openConnection (bool reserveSpace )
47
47
{
48
48
if (initialised) return ;
49
49
initialised = true ;
@@ -75,6 +75,8 @@ void RemoteStore::openConnection()
75
75
if (GET_PROTOCOL_MAJOR (daemonVersion) != GET_PROTOCOL_MAJOR (PROTOCOL_VERSION))
76
76
throw Error (" Nix daemon protocol version not supported" );
77
77
writeInt (PROTOCOL_VERSION, to);
78
+ if (GET_PROTOCOL_MINOR (daemonVersion) >= 11 )
79
+ writeInt (reserveSpace, to);
78
80
processStderr ();
79
81
}
80
82
catch (Error & e) {
@@ -462,7 +464,7 @@ Roots RemoteStore::findRoots()
462
464
463
465
void RemoteStore::collectGarbage (const GCOptions & options, GCResults & results)
464
466
{
465
- openConnection ();
467
+ openConnection (false );
466
468
467
469
writeInt (wopCollectGarbage, to);
468
470
writeInt (options.action , to);
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ private:
86
86
unsigned int daemonVersion;
87
87
bool initialised;
88
88
89
- void openConnection ();
89
+ void openConnection (bool reserveSpace = true );
90
90
91
91
void processStderr (Sink * sink = 0 , Source * source = 0 );
92
92
Original file line number Diff line number Diff line change @@ -322,10 +322,10 @@ namespace nix {
322
322
boost::shared_ptr<StoreAPI> store;
323
323
324
324
325
- boost::shared_ptr<StoreAPI> openStore ()
325
+ boost::shared_ptr<StoreAPI> openStore (bool reserveSpace )
326
326
{
327
327
if (getEnv (" NIX_REMOTE" ) == " " )
328
- return boost::shared_ptr<StoreAPI>(new LocalStore ());
328
+ return boost::shared_ptr<StoreAPI>(new LocalStore (reserveSpace ));
329
329
else
330
330
return boost::shared_ptr<StoreAPI>(new RemoteStore ());
331
331
}
Original file line number Diff line number Diff line change @@ -327,7 +327,7 @@ extern boost::shared_ptr<StoreAPI> store;
327
327
328
328
/* Factory method: open the Nix database, either through the local or
329
329
remote implementation. */
330
- boost::shared_ptr<StoreAPI> openStore ();
330
+ boost::shared_ptr<StoreAPI> openStore (bool reserveSpace = true );
331
331
332
332
333
333
/* Display a set of paths in human-readable form (i.e., between quotes
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ namespace nix {
8
8
#define WORKER_MAGIC_1 0x6e697863
9
9
#define WORKER_MAGIC_2 0x6478696f
10
10
11
- #define PROTOCOL_VERSION 0x10a
11
+ #define PROTOCOL_VERSION 0x10b
12
12
#define GET_PROTOCOL_MAJOR (x ) ((x) & 0xff00 )
13
13
#define GET_PROTOCOL_MINOR (x ) ((x) & 0x00ff )
14
14
Original file line number Diff line number Diff line change @@ -843,7 +843,7 @@ void run(Strings args)
843
843
if (!op) throw UsageError (" no operation specified" );
844
844
845
845
if (op != opDump && op != opRestore) /* !!! hack */
846
- store = openStore ();
846
+ store = openStore (op != opGC );
847
847
848
848
op (opFlags, opArgs);
849
849
}
Original file line number Diff line number Diff line change @@ -625,8 +625,12 @@ static void processConnection()
625
625
throw Error("if you run `nix-worker' as root, then you MUST set `build-users-group'!");
626
626
#endif
627
627
628
+ bool reserveSpace = true ;
629
+ if (GET_PROTOCOL_MINOR (clientVersion) >= 11 )
630
+ reserveSpace = readInt (from) != 0 ;
631
+
628
632
/* Open the store. */
629
- store = boost::shared_ptr<StoreAPI>(new LocalStore ());
633
+ store = boost::shared_ptr<StoreAPI>(new LocalStore (reserveSpace ));
630
634
631
635
stopWork ();
632
636
to.flush ();
You can’t perform that action at this time.
0 commit comments