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

Method Put

engine/db.go:147–173  ·  view source on GitHub ↗

Put write a key-value pair to db, and the key must be not empty

(key []byte, value []byte)

Source from the content-addressed store, hash-verified

145
146// Put write a key-value pair to db, and the key must be not empty
147func (db *DB) Put(key []byte, value []byte) error {
148 zap.L().Info("put", zap.ByteString("key", key), zap.ByteString("value", value))
149 // check key
150 if len(key) == 0 {
151 return _const.ErrKeyIsEmpty
152 }
153
154 // check LogRecord
155 logRecord := &data2.LogRecord{
156 Key: encodeLogRecordKeyWithSeq(key, nonTransactionSeqNo),
157 Value: value,
158 Type: data2.LogRecordNormal,
159 }
160
161 // append log record
162 pos, err := db.appendLogRecordWithLock(logRecord)
163 if err != nil {
164 return err
165 }
166
167 // update index
168 if ok := db.index.Put(key, pos); !ok {
169 return _const.ErrIndexUpdateFailed
170 }
171
172 return nil
173}
174
175// appendLogRecord ethod added lock logic split,
176// to avoid batch write resulting in deadlock problems

Callers 14

TestDB_WriteBatchRestartFunction · 0.95
TestPutAndGetFunction · 0.95
TestDB_PutFunction · 0.95
TestDB_ConcurrentPutFunction · 0.95
TestDB_GetFunction · 0.95
TestDB_DeleteFunction · 0.95
TestDB_GetListKeysFunction · 0.95
TestDB_FoldFunction · 0.95
TestDB_CloseFunction · 0.95
TestDB_SyncFunction · 0.95

Calls 3

PutMethod · 0.65

Tested by 14

TestDB_WriteBatchRestartFunction · 0.76
TestPutAndGetFunction · 0.76
TestDB_PutFunction · 0.76
TestDB_ConcurrentPutFunction · 0.76
TestDB_GetFunction · 0.76
TestDB_DeleteFunction · 0.76
TestDB_GetListKeysFunction · 0.76
TestDB_FoldFunction · 0.76
TestDB_CloseFunction · 0.76
TestDB_SyncFunction · 0.76