Database.Flush() rewrites all table metadata unconditionally (SaveMetadata ignores _metadataDirty) — ~1.45 ms/op on NTFS, ~25 ms/op on ReFS
Les mainteneurs répondent en général sous 2 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- Une demi-journée
- Accessibilité débutants
- 78/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- csharp
- Domaine
- databases, performance
Piste de recherche
Start by reading src/SharpCoreDB/Database/Core/Database.Core.cs, especially Flush(), SaveMetadata(), and _metadataDirty, then compare the flush path with src/SharpCoreDB/DataStructures/Table.cs. Reproduce the difference using the issue's directory-mode write timing steps or by timing Database.Flush() without writes. The work is done when a flush with no metadata changes avoids rewriting meta.dat while DDL changes still persist metadata; no test file is specified in the issue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
Database.Flush() writes the complete database metadata to disk on every call, even when nothing changed. Any caller that flushes per operation (a durable queue write, a log append, a move or a delete) pays a full schema serialization plus a meta.dat rewrite on every row.
Measured on a directory-mode database, 5,000 single-row durable writes, median of 3, net11.0, NTFS: 1,368 ops/sec when the caller uses IDatabase.Flush() versus 2,271 ops/sec with ITable.Flush() — about 1.45 ms of metadata work per operation. On a ReFS volume the same comparison is 184 ops/sec vs 2,127 ops/sec (~24.8 ms per operation), because a synchronous small-file overwrite is far more expensive there.
Where
src/SharpCoreDB/Database/Core/Database.Core.cs (master, checked 2026-11-29):
private bool _metadataDirty;— declared ~line 92, maintained by the DDL paths.public void Flush()(~line 747) ends withSaveMetadata();(~line 796) unconditionally;_metadataDirtyis not consulted (it is only cleared at ~line 797).private void SaveMetadata()(~line 553) builds aTableMetadataDtofor every table (tables.Values.OfType<Table>()), serializes it all to JSON and writes it —_storageProvider.WriteBlockAsync("sys:metadata", …)+FlushAsync()in single-file mode,storage.Write(<db>/meta.dat, metaJson)in directory/legacy mode.
ITable.Flush() (src/SharpCoreDB/DataStructures/Table.cs) only flushes that table's storage engine, so a data-only caller can avoid this today — but nothing in the API signals that IDatabase.Flush() is orders of magnitude heavier, and IDatabase.Flush() is the natural "make it durable" call.
The behaviour predates 2.2.0 (the same SaveMetadata() call is in release/v2.0), so this is not a regression — it is a long-standing cost that becomes visible as soon as a provider flushes per row.
Impact in practice
ServiceMq's SharpCoreDB provider used IDatabase.Flush() as its row-durability barrier. Switching that one line to ITable.Flush() (no data-path change) gave, same machine, NTFS:
| Operation | with IDatabase.Flush() |
with ITable.Flush() |
|---|---|---|
Write (FlushToDisk) |
1,368 ops/sec | 2,271 ops/sec |
| Append | 1,301 ops/sec | 2,157 ops/sec |
| Move | 669 ops/sec | 1,102 ops/sec |
| Delete | 1,346 ops/sec | 2,182 ops/sec |
Durability of the ITable.Flush() path was verified independently: 100 durable rows, then Process.Kill() with no Dispose and no graceful close, then a fresh process reopening the store — 100/100 rows present.
Reproduction
- Directory mode:
new DatabaseFactory(services).Create(path, password, false, new DatabaseConfig { AutoFixedWidthRecords = false }). - Write 5,000 rows through
ITable.Insert, timing two variants:table.Flush()per insert versusdatabase.Flush()per insert. - Isolate further by timing N
database.Flush()calls with no writes at all — each still serializes the schema and rewritesmeta.dat.
This also biases any engine benchmark that calls db.Flush() inside the timed region: the per-flush metadata save is a separate, avoidable component of "commit" cost.
Suggested fix
- Consult
_metadataDirtyinFlush()and skipSaveMetadata()when no DDL changed (cheap, keeps the public contract). - Track a per-table schema version so
SaveMetadata()re-serializes only tables whose schema actually changed; the DTO carries column arrays, constraints, collations and inline-capacity flags that DML never touches. - Optionally make intent explicit (
FlushData()vsFlushSchema()) and/or document onIDatabase.Flush()that it persists metadata too.
Happy to re-run the ServiceMq benchmark harness against any build to confirm the numbers.
- Langage dominant
- C#
- Étoiles
- 42
- Forks
- 6
- Merge moyen
- 4 j 12 h
- PR mergées (30 j)
- 24
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de MPCoreDeveloper/SharpCoreDB
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
MPCoreDeveloper/SharpCoreDB#531 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
Future idea with more examples/samples/toolPeut-être à nouveau libre @MPCoreDeveloper l’a pris il y a 230 jours, et aucune pull request n’est ouverte. Ouvertearea:docs area:security area:viewer documentation enhancement good first issue
MPCoreDeveloper/SharpCoreDB#171 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de MPCoreDeveloper/SharpCoreDB
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
martin-stromberg/FinanceManager#628 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
Left Hand Margin Too NarrowOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
builtbybel/FluentCleaner#266 ·
Les mainteneurs répondent en général sous 2 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 2 jours