func (s *FileStore) storeLog(l *Log) error { err := s.w.StoreLog(l) if err == nil { return nil } else if err != errTableNeedFlush { return err } var r *tableReader r, err = s.w.Flush() if err != nil { log.Fatalf("write table flush error %s, can not store!!!", err.Error()) s.w.Close() return err } s.rm.Lock() s.rs = append(s.rs, r) s.rm.Unlock() err = s.w.StoreLog(l) return err }
func (t *tableWriter) close() { if t.meta != nil { if err := t.meta.Close(); err != nil { log.Fatalf("close log meta error %s", err.Error()) } t.meta = nil } if t.data != nil { if _, err := t.data.Write(magic); err != nil { log.Fatalf("write magic error %s", err.Error()) } if err := t.data.Close(); err != nil { log.Fatalf("close log data error %s", err.Error()) } t.data = nil } }
func (l *Ledis) handleCommit(g commitDataGetter, c commiter) error { l.commitLock.Lock() var err error if l.r != nil { var rl *rpl.Log if rl, err = l.r.Log(g.Data()); err != nil { l.commitLock.Unlock() log.Fatalf("write wal error %s", err.Error()) return err } l.propagate(rl) if err = c.Commit(); err != nil { l.commitLock.Unlock() log.Fatalf("commit error %s", err.Error()) l.noticeReplication() return err } if err = l.r.UpdateCommitID(rl.ID); err != nil { l.commitLock.Unlock() log.Fatalf("update commit id error %s", err.Error()) l.noticeReplication() return err } } else { err = c.Commit() } l.commitLock.Unlock() return err }
func (l *Ledis) flushAll() error { it := l.ldb.NewIterator() defer it.Close() it.SeekToFirst() w := l.ldb.NewWriteBatch() defer w.Rollback() n := 0 for ; it.Valid(); it.Next() { n++ if n == 10000 { if err := w.Commit(); err != nil { log.Fatalf("flush all commit error: %s", err.Error()) return err } n = 0 } w.Delete(it.RawKey()) } if err := w.Commit(); err != nil { log.Fatalf("flush all commit error: %s", err.Error()) return err } if l.r != nil { if err := l.r.Clear(); err != nil { log.Fatalf("flush all replication clear error: %s", err.Error()) return err } } return nil }
func (db *DB) lSetMeta(ek []byte, headSeq int32, tailSeq int32) int32 { t := db.listBatch var size int32 = tailSeq - headSeq + 1 if size < 0 { // todo : log error + panic log.Fatalf("invalid meta sequence range [%d, %d]", headSeq, tailSeq) } else if size == 0 { t.Delete(ek) } else { buf := make([]byte, 8) binary.LittleEndian.PutUint32(buf[0:4], uint32(headSeq)) binary.LittleEndian.PutUint32(buf[4:8], uint32(tailSeq)) t.Put(ek, buf) } return size }