Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
maurodelazeri committed Jan 6, 2023
1 parent 966729e commit 4df38d4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions leveldb/db_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package leveldb

import (
"fmt"
"sync/atomic"
"time"

Expand Down Expand Up @@ -152,6 +153,8 @@ func (db *DB) unlockWrite(overflow bool, merged int, err error) {

// ourBatch is batch that we can modify.
func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
fmt.Println("leveldb writeLocked")

// Try to flush memdb. This method would also trying to throttle writes
// if it is too fast and compaction cannot catch-up.
mdb, mdbFree, err := db.flush(batch.internalLen)
Expand Down Expand Up @@ -264,6 +267,8 @@ func (db *DB) writeLocked(batch, ourBatch *Batch, merge, sync bool) error {
// It is safe to modify the contents of the arguments after Write returns but
// not before. Write will not modify content of the batch.
func (db *DB) Write(batch *Batch, wo *opt.WriteOptions) error {
fmt.Println("leveldb Write")

if err := db.ok(); err != nil || batch == nil || batch.Len() == 0 {
return err
}
Expand Down Expand Up @@ -321,6 +326,8 @@ func (db *DB) Write(batch *Batch, wo *opt.WriteOptions) error {
}

func (db *DB) putRec(kt keyType, key, value []byte, wo *opt.WriteOptions) error {
fmt.Println("leveldb putRec", kt.String(), string(key), string(value))

if err := db.ok(); err != nil {
return err
}
Expand Down Expand Up @@ -372,6 +379,7 @@ func (db *DB) putRec(kt keyType, key, value []byte, wo *opt.WriteOptions) error
// It is safe to modify the contents of the arguments after Put returns but not
// before.
func (db *DB) Put(key, value []byte, wo *opt.WriteOptions) error {
fmt.Println("leveldb PUT", string(key), string(value))
return db.putRec(keyTypeVal, key, value, wo)
}

Expand All @@ -381,6 +389,7 @@ func (db *DB) Put(key, value []byte, wo *opt.WriteOptions) error {
// It is safe to modify the contents of the arguments after Delete returns but
// not before.
func (db *DB) Delete(key []byte, wo *opt.WriteOptions) error {
fmt.Println("leveldb Delete", string(key))
return db.putRec(keyTypeDel, key, nil, wo)
}

Expand Down

0 comments on commit 4df38d4

Please sign in to comment.