Skip to content

Commit 7d2f618

Browse files
committed
Making the scope slightly smaller
1 parent 3a1fcf0 commit 7d2f618

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

LiteDB/Engine/Services/RebuildService.cs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,46 +51,38 @@ public long Rebuild(RebuildOptions options)
5151
// open file reader and ready to import to new temp engine instance
5252
reader.Open();
5353

54-
try
54+
// open new engine to recive all data readed from FileReader
55+
using var engine = new LiteEngine(new EngineSettings
5556
{
56-
// open new engine to recive all data readed from FileReader
57-
using var engine = new LiteEngine(new EngineSettings
58-
{
59-
Filename = tempFilename,
60-
Collation = options.Collation,
61-
Password = options.Password,
62-
});
63-
// copy all database to new Log file with NO checkpoint during all rebuild
64-
engine.Pragma(Pragmas.CHECKPOINT, 0);
65-
66-
// rebuild all content from reader into new engine
67-
engine.RebuildContent(reader);
68-
69-
// insert error report
70-
if (options.IncludeErrorReport && options.Errors.Count > 0)
71-
{
72-
var report = options.GetErrorReport();
73-
74-
engine.Insert("_rebuild_errors", report, BsonAutoId.Int32);
75-
}
76-
77-
// update pragmas
78-
var pragmas = reader.GetPragmas();
79-
80-
engine.Pragma(Pragmas.CHECKPOINT, pragmas[Pragmas.CHECKPOINT]);
81-
engine.Pragma(Pragmas.TIMEOUT, pragmas[Pragmas.TIMEOUT]);
82-
engine.Pragma(Pragmas.LIMIT_SIZE, pragmas[Pragmas.LIMIT_SIZE]);
83-
engine.Pragma(Pragmas.UTC_DATE, pragmas[Pragmas.UTC_DATE]);
84-
engine.Pragma(Pragmas.USER_VERSION, pragmas[Pragmas.USER_VERSION]);
85-
86-
// after rebuild, copy log bytes into data file
87-
engine.Checkpoint();
88-
}
89-
catch (Exception)
57+
Filename = tempFilename,
58+
Collation = options.Collation,
59+
Password = options.Password,
60+
});
61+
// copy all database to new Log file with NO checkpoint during all rebuild
62+
engine.Pragma(Pragmas.CHECKPOINT, 0);
63+
64+
// rebuild all content from reader into new engine
65+
engine.RebuildContent(reader);
66+
67+
// insert error report
68+
if (options.IncludeErrorReport && options.Errors.Count > 0)
9069
{
91-
File.Delete(tempFilename);
92-
throw;
70+
var report = options.GetErrorReport();
71+
72+
engine.Insert("_rebuild_errors", report, BsonAutoId.Int32);
9373
}
74+
75+
// update pragmas
76+
var pragmas = reader.GetPragmas();
77+
78+
engine.Pragma(Pragmas.CHECKPOINT, pragmas[Pragmas.CHECKPOINT]);
79+
engine.Pragma(Pragmas.TIMEOUT, pragmas[Pragmas.TIMEOUT]);
80+
engine.Pragma(Pragmas.LIMIT_SIZE, pragmas[Pragmas.LIMIT_SIZE]);
81+
engine.Pragma(Pragmas.UTC_DATE, pragmas[Pragmas.UTC_DATE]);
82+
engine.Pragma(Pragmas.USER_VERSION, pragmas[Pragmas.USER_VERSION]);
83+
84+
// after rebuild, copy log bytes into data file
85+
engine.Checkpoint();
9486
}
9587

9688
// if log file exists, rename as backup file

0 commit comments

Comments
 (0)