예제 #1
0
파일: entry.go 프로젝트: 6londe/FactomCode
// InsertEntry inserts an entry
func (db *LevelDb) InsertEntry(entry *common.Entry) error {
	db.dbLock.Lock()
	defer db.dbLock.Unlock()

	if db.lbatch == nil {
		db.lbatch = new(leveldb.Batch)
	}
	defer db.lbatch.Reset()

	binaryEntry, err := entry.MarshalBinary()
	if err != nil {
		return err
	}
	var entryKey []byte = []byte{byte(TBL_ENTRY)}
	entryKey = append(entryKey, entry.Hash().Bytes()...)
	db.lbatch.Put(entryKey, binaryEntry)

	err = db.lDb.Write(db.lbatch, db.wo)
	if err != nil {
		log.Println("batch failed %v\n", err)
		return err
	}

	return nil
}
예제 #2
0
func (db *LevelDb) InsertEntryMultiBatch(entry *common.Entry) error {
	if entry == nil {
		return nil
	}

	if db.lbatch == nil {
		return fmt.Errorf("db.lbatch == nil")
	}

	binaryEntry, err := entry.MarshalBinary()
	if err != nil {
		return err
	}
	var entryKey []byte = []byte{byte(TBL_ENTRY)}
	entryKey = append(entryKey, entry.Hash().Bytes()...)
	db.lbatch.Put(entryKey, binaryEntry)

	return nil
}