Exemplo n.º 1
0
// Put puts the given key / value to the queue
func (self *LDBDatabase) Put(key []byte, value []byte) error {
	// Measure the database put latency, if requested
	if self.PutTimer != nil {
		defer self.PutTimer.UpdateSince(time.Now())
	}
	// Generate the data to write to disk, update the meter and write
	dat := rle.Compress(value)

	if self.WriteMeter != nil {
		self.WriteMeter.Mark(int64(len(dat)))
	}
	return self.db.Put(key, dat, nil)
}
Exemplo n.º 2
0
func (self *LDBDatabase) Flush() error {
	self.mu.Lock()
	defer self.mu.Unlock()

	batch := new(leveldb.Batch)

	for key, value := range self.queue {
		batch.Put([]byte(key), rle.Compress(value))
	}
	self.makeQueue() // reset the queue

	glog.V(logger.Detail).Infoln("Flush database: ", self.fn)

	return self.db.Write(batch, nil)
}
Exemplo n.º 3
0
func (self *ChainManager) flushQueuedBlocks() {
	db, batchWrite := self.blockDb.(*ethdb.LDBDatabase)
	batch := new(leveldb.Batch)
	for _, key := range self.pendingBlocks.Keys() {
		b, _ := self.pendingBlocks.Get(key)
		block := b.(*types.Block)

		enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block))
		key := append(blockHashPre, block.Hash().Bytes()...)
		if batchWrite {
			batch.Put(key, rle.Compress(enc))
		} else {
			self.blockDb.Put(key, enc)
		}
	}

	if batchWrite {
		db.LDB().Write(batch, nil)
	}
}
Exemplo n.º 4
0
func (self *Cache) Put(key []byte, data []byte) {
	// write the data to the ldb batch
	self.batch.Put(key, rle.Compress(data))
	self.store[string(key)] = data
}
Exemplo n.º 5
0
// Put puts the given key / value to the queue
func (self *LDBDatabase) Put(key []byte, value []byte) error {
	return self.db.Put(key, rle.Compress(value), nil)
}