本文整理汇总了Golang中github.com/tecbot/gorocksdb.NewDefaultWriteOptions函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDefaultWriteOptions函数的具体用法?Golang NewDefaultWriteOptions怎么用?Golang NewDefaultWriteOptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDefaultWriteOptions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CommitTxBatch
// CommitTxBatch - gets invoked when the current transaction-batch needs to be committed
// This function returns successfully iff the transactions details and state changes (that
// may have happened during execution of this transaction-batch) have been committed to permanent storage
func (ledger *Ledger) CommitTxBatch(id interface{}, transactions []*protos.Transaction, proof []byte) error {
err := ledger.checkValidIDCommitORRollback(id)
if err != nil {
return err
}
success := true
defer ledger.resetForNextTxGroup(success)
defer ledger.blockchain.blockPersistenceStatus(success)
stateHash, err := ledger.state.GetHash()
if err != nil {
success = false
return err
}
writeBatch := gorocksdb.NewWriteBatch()
block := protos.NewBlock(transactions)
newBlockNumber, err := ledger.blockchain.addPersistenceChangesForNewBlock(context.TODO(), block, stateHash, writeBatch)
if err != nil {
success = false
return err
}
ledger.state.AddChangesForPersistence(newBlockNumber, writeBatch)
opt := gorocksdb.NewDefaultWriteOptions()
dbErr := db.GetDBHandle().DB.Write(opt, writeBatch)
if dbErr != nil {
success = false
return dbErr
}
producer.Send(producer.CreateBlockEvent(block))
return nil
}
示例2: RedisDel
func (rh *RocksDBHandler) RedisDel(key []byte, keys ...[]byte) (int, error) {
if rh.db == nil {
return 0, ErrRocksIsDead
}
if key == nil || len(key) == 0 {
return 0, ErrWrongArgumentsCount
}
keyData := append([][]byte{key}, keys...)
count := 0
readOptions := rocks.NewDefaultReadOptions()
writeOptions := rocks.NewDefaultWriteOptions()
defer readOptions.Destroy()
defer writeOptions.Destroy()
for _, dKey := range keyData {
_, err := rh.loadRedisObject(readOptions, dKey)
if err == nil {
batch := rocks.NewWriteBatch()
batch.Delete(rh.getTypeKey(dKey))
batch.Delete(dKey)
if err := rh.db.Write(writeOptions, batch); err == nil {
count++
}
batch.Destroy()
}
}
return count, nil
}
示例3: WriteToDB
// WriteToDB tests can use this method for persisting a given batch to db
func (testDB *TestDBWrapper) WriteToDB(t *testing.T, writeBatch *gorocksdb.WriteBatch) {
opt := gorocksdb.NewDefaultWriteOptions()
err := GetDBHandle().DB.Write(opt, writeBatch)
if err != nil {
t.Fatalf("Error while writing to db. Error:%s", err)
}
}
示例4: _list_doMerge
func (rh *RocksDBHandler) _list_doMerge(key []byte, value interface{}, opCode string, start, end int) error {
var values [][]byte
if d1Slice, ok := value.([]byte); ok {
values = [][]byte{d1Slice}
}
if d2Slice, ok := value.([][]byte); ok {
values = d2Slice
}
if values == nil || len(values) == 0 {
return ErrWrongArgumentsCount
}
options := rocks.NewDefaultWriteOptions()
defer options.Destroy()
batch := rocks.NewWriteBatch()
defer batch.Destroy()
batch.Put(rh.getTypeKey(key), []byte(kRedisList))
for _, dValue := range values {
operand := ListOperand{opCode, start, end, dValue}
if data, err := encode(operand); err == nil {
batch.Merge(key, data)
} else {
return err
}
}
return rh.db.Write(options, batch)
}
示例5: doPut
func doPut(db *gorocksdb.DB, from int, to int) <-chan putStat {
var totalTime time.Duration
var maxTime time.Duration
putCount := 0
loopCount := 100000
putStatCh := make(chan putStat)
wo := gorocksdb.NewDefaultWriteOptions()
go func() {
for {
key := []byte(uuid.NewV4().String())
value := randBytes(from, to)
start := time.Now()
err := db.Put(wo, key, value)
if err != nil {
fmt.Println("dbPut error : ", err)
os.Exit(1)
}
delta := time.Since(start)
if delta > maxTime {
maxTime = delta
}
totalTime += delta
putCount++
if (putCount % loopCount) == 0 {
avgTime := totalTime / time.Duration(loopCount)
putStatCh <- putStat{maxTime, avgTime}
maxTime = 0
totalTime = 0
}
}
}()
return putStatCh
}
示例6: write_multi_cfs
func write_multi_cfs() error {
dbOpts := gorocksdb.NewDefaultOptions()
dbOpts.SetCreateIfMissing(true)
if err := os.RemoveAll("/tmp/multicf_db"); err != nil {
return err
}
db, err := gorocksdb.OpenDb(dbOpts, "/tmp/multicf_db")
if err != nil {
return err
}
var handles []*gorocksdb.ColumnFamilyHandle
for i := 0; i < 4; i++ {
handle, err := db.CreateColumnFamily(dbOpts, fmt.Sprint(i))
if err != nil {
return err
}
handles = append(handles, handle)
}
writeOpts := gorocksdb.NewDefaultWriteOptions()
if err := db.Put(writeOpts, []byte("default"), []byte("default")); err != nil {
return err
}
for i := 0; i < 16; i++ {
key := []byte(fmt.Sprint(i))
if err := db.PutCF(writeOpts, handles[i%4], key, key); err != nil {
return err
}
}
db.Close()
return nil
}
示例7: persistRawBlock
func (blockchain *blockchain) persistRawBlock(block *protos.Block, blockNumber uint64) error {
blockBytes, blockBytesErr := block.Bytes()
if blockBytesErr != nil {
return blockBytesErr
}
writeBatch := gorocksdb.NewWriteBatch()
defer writeBatch.Destroy()
writeBatch.PutCF(db.GetDBHandle().BlockchainCF, encodeBlockNumberDBKey(blockNumber), blockBytes)
blockHash, err := block.GetHash()
if err != nil {
return err
}
// Need to check as we suport out of order blocks in cases such as block/state synchronization. This is
// really blockchain height, not size.
if blockchain.getSize() < blockNumber+1 {
sizeBytes := encodeUint64(blockNumber + 1)
writeBatch.PutCF(db.GetDBHandle().BlockchainCF, blockCountKey, sizeBytes)
blockchain.size = blockNumber + 1
blockchain.previousBlockHash = blockHash
}
if blockchain.indexer.isSynchronous() {
blockchain.indexer.createIndexesSync(block, blockNumber, blockHash, writeBatch)
}
opt := gorocksdb.NewDefaultWriteOptions()
defer opt.Destroy()
err = db.GetDBHandle().DB.Write(opt, writeBatch)
if err != nil {
return err
}
return nil
}
示例8: NewRocksdbStorage
func NewRocksdbStorage(dbfname string, dbtype string, mergeOp gorocksdb.MergeOperator) (*RocksdbStorage, error) {
var sto *RocksdbStorage
if dbtype != "kv" && dbtype != "json" {
return sto, fmt.Errorf("Unkown db type")
}
opts := gorocksdb.NewDefaultOptions()
if mergeOp != nil {
opts.SetMergeOperator(mergeOp)
}
// opts.IncreaseParallelism(runtime.NumCPU())
// opts.OptimizeLevelStyleCompaction(0)
opts.SetCreateIfMissing(true)
db, err := gorocksdb.OpenDb(opts, dbfname)
if err != nil {
return sto, err
}
ro := gorocksdb.NewDefaultReadOptions()
wo := gorocksdb.NewDefaultWriteOptions()
sto = &RocksdbStorage{
dbfname: dbfname,
db: db,
ro: ro,
wo: wo,
}
return sto, nil
}
示例9: New
func New(rdb *gorocksdb.DB) *DB {
db := &DB{rdb: rdb}
db.wo = gorocksdb.NewDefaultWriteOptions()
db.ro = gorocksdb.NewDefaultReadOptions()
db.caches = lru.New(1000)
db.RawSet([]byte{MAXBYTE}, nil) // for Enumerator seek to last
return db
}
示例10: RedisSet
func (rh *RocksDBHandler) RedisSet(key, value []byte) error {
if err := rh.checkRedisCall(key, value); err != nil {
return err
}
options := rocks.NewDefaultWriteOptions()
defer options.Destroy()
return rh.saveRedisObject(options, key, value, kRedisString)
}
示例11: Delete
func (openchainDB *OpenchainDB) Delete(cfHandler *gorocksdb.ColumnFamilyHandle, key []byte) error {
opt := gorocksdb.NewDefaultWriteOptions()
defer opt.Destroy()
err := openchainDB.DB.DeleteCF(opt, cfHandler, key)
if err != nil {
fmt.Println("Error while trying to delete key:", key)
return err
}
return nil
}
示例12: Put
// Put saves the key/value in the given column family
func (openchainDB *OpenchainDB) Put(cfHandler *gorocksdb.ColumnFamilyHandle, key []byte, value []byte) error {
opt := gorocksdb.NewDefaultWriteOptions()
defer opt.Destroy()
err := openchainDB.DB.PutCF(opt, cfHandler, key, value)
if err != nil {
dbLogger.Errorf("Error while trying to write key: %s", key)
return err
}
return nil
}
示例13: CommitStateDelta
// CommitStateDelta commits the changes from state.ApplyStateDelta to the
// DB.
func (state *State) CommitStateDelta() error {
if state.updateStateImpl {
state.stateImpl.PrepareWorkingSet(state.stateDelta)
state.updateStateImpl = false
}
writeBatch := gorocksdb.NewWriteBatch()
state.stateImpl.AddChangesForPersistence(writeBatch)
opt := gorocksdb.NewDefaultWriteOptions()
return db.GetDBHandle().DB.Write(opt, writeBatch)
}
示例14: createIndexesInternal
// createIndexes adds entries into db for creating indexes on various atributes
func (indexer *blockchainIndexerAsync) createIndexesInternal(block *protos.Block, blockNumber uint64, blockHash []byte) error {
openchainDB := db.GetDBHandle()
writeBatch := gorocksdb.NewWriteBatch()
addIndexDataForPersistence(block, blockNumber, blockHash, writeBatch)
writeBatch.PutCF(openchainDB.IndexesCF, lastIndexedBlockKey, encodeBlockNumber(blockNumber))
opt := gorocksdb.NewDefaultWriteOptions()
err := openchainDB.DB.Write(opt, writeBatch)
if err != nil {
return err
}
indexer.indexerState.blockIndexed(blockNumber)
return nil
}
示例15: _string_doMerge
func (rh *RocksDBHandler) _string_doMerge(key, value []byte, opCode string) error {
options := rocks.NewDefaultWriteOptions()
defer options.Destroy()
batch := rocks.NewWriteBatch()
defer batch.Destroy()
batch.Put(rh.getTypeKey(key), []byte(kRedisString))
operand := StringOperand{opCode, value}
if data, err := encode(operand); err != nil {
return err
} else {
batch.Merge(key, data)
}
return rh.db.Write(options, batch)
}