Ejemplo n.º 1
0
// 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
}
Ejemplo n.º 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
}