MCPcopy Index your code
hub / github.com/ByteStorage/FlyDB / Delete

Method Delete

engine/batch.go:57–85  ·  view source on GitHub ↗

Delete Batch deletion of data

(key []byte)

Source from the content-addressed store, hash-verified

55
56// Delete Batch deletion of data
57func (wb *WriteBatch) Delete(key []byte) error {
58 // Check if the key is empty
59 if len(key) == 0 {
60 return _const.ErrKeyIsEmpty
61 }
62
63 // Acquire a lock to ensure thread safety
64 wb.lock.Lock()
65 defer wb.lock.Unlock()
66
67 // If the data does not exist, delete it from
68 // temporaryDataWrites if present and return directly
69 logRecordPst := wb.db.index.Get(key)
70 if logRecordPst == nil {
71 if wb.temporaryDataWrites[string(key)] != nil {
72 delete(wb.temporaryDataWrites, string(key))
73 }
74 return nil
75 }
76
77 // Temporarily store the LogRecord
78 logRecord := &data.LogRecord{
79 Key: key,
80 Type: data.LogRecordDeleted,
81 }
82 wb.temporaryDataWrites[string(key)] = logRecord
83
84 return nil
85}
86
87// Commit The transaction commits, writes the transient data to the data file, and updates the in-memory index
88func (wb *WriteBatch) Commit() error {

Callers 5

TestDB_WriteBatchFunction · 0.95
TestDB_WriteBatchRestartFunction · 0.95
HDelMethod · 0.95
HDelAllMethod · 0.95
HMoveMethod · 0.95

Calls 1

GetMethod · 0.65

Tested by 2

TestDB_WriteBatchFunction · 0.76
TestDB_WriteBatchRestartFunction · 0.76