Browse Source

bulkdata: write _format file atomically, to reduce chance of corruption

Some databases were seeing _format truncated to 0 bytes, after crashing
soon after a new stream was created (e.g. during decimation).
tags/nilmdb-2.2.0
Jim Paris 3 years ago
parent
commit
759492298a
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      nilmdb/server/bulkdata.py

+ 2
- 2
nilmdb/server/bulkdata.py View File

@@ -293,8 +293,8 @@ class Table():
"layout": layout, "layout": layout,
"version": 3 "version": 3
} }
with open(os.path.join(root, b"_format"), "wb") as f:
pickle.dump(fmt, f, 2)
nilmdb.utils.atomic.replace_file(
os.path.join(root, b"_format"), pickle.dumps(fmt, 2))


# Normal methods # Normal methods
def __init__(self, root, initial_nrows=0): def __init__(self, root, initial_nrows=0):


Loading…
Cancel
Save