示例#1
0
// writeBatch applies the puts, merges and deletes atomically via
// the RocksDB write batch facility. The list must only contain
// elements of type Batch{Put,Merge,Delete}.
func (r *RocksDB) writeBatch(cmds []interface{}) error {
	if len(cmds) == 0 {
		return nil
	}
	batch := C.rocksdb_writebatch_create()
	defer C.rocksdb_writebatch_destroy(batch)
	for i, e := range cmds {
		switch v := e.(type) {
		case BatchDelete:
			if len(v) == 0 {
				return emptyKeyError()
			}
			C.rocksdb_writebatch_delete(
				batch,
				(*C.char)(unsafe.Pointer(&v[0])),
				C.size_t(len(v)))
		case BatchPut:
			key, value := v.Key, v.Value
			valuePointer := (*C.char)(nil)
			if len(value.Bytes) > 0 {
				valuePointer = (*C.char)(unsafe.Pointer(&value.Bytes[0]))
			}

			// We write the batch before returning from this method, so we
			// don't need to worry about the GC reclaiming the data stored.
			C.rocksdb_writebatch_put(
				batch,
				(*C.char)(unsafe.Pointer(&key[0])),
				C.size_t(len(key)),
				valuePointer,
				C.size_t(len(value.Bytes)))
		case BatchMerge:
			key, value := v.Key, v.Value
			valuePointer := (*C.char)(nil)
			if len(value.Bytes) > 0 {
				valuePointer = (*C.char)(unsafe.Pointer(&value.Bytes[0]))
			}
			C.rocksdb_writebatch_merge(
				batch,
				(*C.char)(unsafe.Pointer(&key[0])),
				C.size_t(len(key)),
				valuePointer,
				C.size_t(len(value.Bytes)))
		default:
			panic(fmt.Sprintf("illegal operation #%d passed to writeBatch: %v", i, reflect.TypeOf(v)))
		}
	}

	var cErr *C.char
	C.rocksdb_write(r.rdb, r.wOpts, batch, &cErr)
	if cErr != nil {
		return charToErr(cErr)
	}
	return nil
}
示例#2
0
// writeBatch applies all puts and deletes atomically via RocksDB write
// batch facility.
func (r *RocksDB) writeBatch(puts []KeyValue, dels []Key) error {
	batch := C.rocksdb_writebatch_create()
	defer C.rocksdb_writebatch_destroy(batch)

	for _, put := range puts {
		key, value := put.Key, put.Value
		if len(key) == 0 {
			return emptyKeyError()
		}

		// Empty values correspond to a null pointer.
		valuePointer := (*C.char)(nil)
		if len(value.Bytes) > 0 {
			valuePointer = (*C.char)(unsafe.Pointer(&value.Bytes[0]))
		}

		// We write the batch before returning from this method, so we
		// don't need to worry about the GC reclaiming the data stored in
		// the "puts" and "dels" parameters.
		C.rocksdb_writebatch_put(
			batch,
			(*C.char)(unsafe.Pointer(&key[0])),
			C.size_t(len(key)),
			valuePointer,
			C.size_t(len(value.Bytes)))
	}

	for _, key := range dels {
		if len(key) == 0 {
			return emptyKeyError()
		}
		C.rocksdb_writebatch_delete(
			batch,
			(*C.char)(unsafe.Pointer(&key[0])),
			C.size_t(len(key)))
	}

	var cErr *C.char
	C.rocksdb_write(r.rdb, r.wOpts, batch, &cErr)
	if cErr != nil {
		return charToErr(cErr)
	}

	return nil
}
示例#3
0
// Release deallocates the WriteBatch object.
func (w *WriteBatch) Release() {
	C.rocksdb_writebatch_destroy(w.c)
	w.c = nil
}
示例#4
0
文件: batch.go 项目: Abioy/ledisdb
func (w *WriteBatch) Close() error {
	C.rocksdb_writebatch_destroy(w.wbatch)
	w.wbatch = nil
	return nil
}
示例#5
0
// Close releases the underlying memory of a WriteBatch.
func (w *WriteBatch) Close() {
	C.rocksdb_writebatch_destroy(w.wbatch)
}
示例#6
0
// Destroy deallocates the WriteBatch object.
func (self *WriteBatch) Destroy() {
	C.rocksdb_writebatch_destroy(self.c)
	self.c = nil
}
示例#7
0
// Destroy deallocates the WriteBatch object.
func (wb *WriteBatch) Destroy() {
	C.rocksdb_writebatch_destroy(wb.c)
	wb.c = nil
}
示例#8
0
func (w *WriteBatch) Close() {
	if w.wbatch != nil {
		C.rocksdb_writebatch_destroy(w.wbatch)
		w.wbatch = nil
	}
}
示例#9
0
文件: db.go 项目: tradia/gotable
func (wb *WriteBatch) Destroy() {
	if wb.batch != nil {
		C.rocksdb_writebatch_destroy(wb.batch)
		wb.batch = nil
	}
}