diff --git a/ledis/dump.go b/ledis/dump.go index 1f6d5e2..863255c 100644 --- a/ledis/dump.go +++ b/ledis/dump.go @@ -155,6 +155,11 @@ func (l *Ledis) LoadDump(r io.Reader) (*DumpHead, error) { var key, value []byte + wb := l.ldb.NewWriteBatch() + defer wb.Close() + + n := 0 + for { if err = binary.Read(rb, binary.BigEndian, &keyLen); err != nil && err != io.EOF { return nil, err @@ -182,14 +187,26 @@ func (l *Ledis) LoadDump(r io.Reader) (*DumpHead, error) { return nil, err } - if err = l.ldb.Put(key, value); err != nil { - return nil, err + wb.Put(key, value) + n++ + if n%1024 == 0 { + if err = wb.Commit(); err != nil { + return nil, err + } } + // if err = l.ldb.Put(key, value); err != nil { + // return nil, err + // } + keyBuf.Reset() valueBuf.Reset() } + if err = wb.Commit(); err != nil { + return nil, err + } + deKeyBuf = nil deValueBuf = nil