Delete Batch deletion of data
(key []byte)
| 55 | |
| 56 | // Delete Batch deletion of data |
| 57 | func (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 |
| 88 | func (wb *WriteBatch) Commit() error { |