forked from mirror/ledisdb
fix LevelDB CGO panic (#285)
This commit is contained in:
parent
6ad692d5e1
commit
5929802e2e
|
@ -74,6 +74,8 @@ func NewReplication(cfg *config.Config) (*Replication, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("staring replication with commit ID %d", r.commitID)
|
||||||
|
|
||||||
r.wg.Add(1)
|
r.wg.Add(1)
|
||||||
go r.run()
|
go r.run()
|
||||||
|
|
||||||
|
@ -88,6 +90,8 @@ func (r *Replication) Close() error {
|
||||||
r.m.Lock()
|
r.m.Lock()
|
||||||
defer r.m.Unlock()
|
defer r.m.Unlock()
|
||||||
|
|
||||||
|
log.Infof("closing replication with commit ID %d", r.commitID)
|
||||||
|
|
||||||
if r.s != nil {
|
if r.s != nil {
|
||||||
r.s.Close()
|
r.s.Close()
|
||||||
r.s = nil
|
r.s = nil
|
||||||
|
|
|
@ -16,15 +16,12 @@ import (
|
||||||
type WriteBatch struct {
|
type WriteBatch struct {
|
||||||
db *DB
|
db *DB
|
||||||
wbatch *C.leveldb_writebatch_t
|
wbatch *C.leveldb_writebatch_t
|
||||||
|
|
||||||
gbatch *leveldb.Batch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWriteBatch(db *DB) *WriteBatch {
|
func newWriteBatch(db *DB) *WriteBatch {
|
||||||
w := new(WriteBatch)
|
w := new(WriteBatch)
|
||||||
w.db = db
|
w.db = db
|
||||||
w.wbatch = C.leveldb_writebatch_create()
|
w.wbatch = C.leveldb_writebatch_create()
|
||||||
w.gbatch = new(leveldb.Batch)
|
|
||||||
|
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
@ -34,8 +31,6 @@ func (w *WriteBatch) Close() {
|
||||||
C.leveldb_writebatch_destroy(w.wbatch)
|
C.leveldb_writebatch_destroy(w.wbatch)
|
||||||
w.wbatch = nil
|
w.wbatch = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
w.gbatch = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WriteBatch) Put(key, value []byte) {
|
func (w *WriteBatch) Put(key, value []byte) {
|
||||||
|
@ -97,9 +92,8 @@ func leveldb_writebatch_iterate_delete(p unsafe.Pointer, k *C.char, klen C.size_
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WriteBatch) Data() []byte {
|
func (w *WriteBatch) Data() []byte {
|
||||||
w.gbatch.Reset()
|
gbatch := leveldb.Batch{}
|
||||||
C.leveldb_writebatch_iterate_ext(w.wbatch,
|
C.leveldb_writebatch_iterate_ext(w.wbatch,
|
||||||
unsafe.Pointer(w.gbatch))
|
unsafe.Pointer(&gbatch))
|
||||||
b := w.gbatch.Dump()
|
return gbatch.Dump()
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue