MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / Delete

Method Delete

engine/db.go:348–379  ·  view source on GitHub ↗

Delete data according to the key

(key []byte)

Source from the content-addressed store, hash-verified

346
347// Delete data according to the key
348func (db *DB) Delete(key []byte) error {
349 zap.L().Info("delete", zap.ByteString("key", key))
350
351 // Determine the validity of the key
352 if len(key) == 0 {
353 return _const.ErrKeyIsEmpty
354 }
355
356 // Check whether the key exists. If it does not exist, return it
357 if pst := db.index.Get(key); pst == nil {
358 return nil
359 }
360
361 // Construct a logRecord to indicate that it was deleted
362 logRecord := &data2.LogRecord{
363 Key: encodeLogRecordKeyWithSeq(key, nonTransactionSeqNo),
364 Type: data2.LogRecordDeleted,
365 }
366
367 // Write to the data file
368 _, err := db.appendLogRecordWithLock(logRecord)
369 if err != nil {
370 return err
371 }
372
373 // Removes key from memory index
374 ok := db.index.Delete(key)
375 if !ok {
376 return _const.ErrIndexUpdateFailed
377 }
378 return nil
379}
380
381// Load the data file from disk
382func (db *DB) loadDataFiles() error {

Callers 3

TestDB_GetFunction · 0.95
TestDB_DeleteFunction · 0.95
TestDB_Merge3Function · 0.95

Calls 4

GetMethod · 0.65
DeleteMethod · 0.65

Tested by 3

TestDB_GetFunction · 0.76
TestDB_DeleteFunction · 0.76
TestDB_Merge3Function · 0.76