コード例 #1
0
ファイル: test.go プロジェクト: krishnasrinivas/random-progs
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
}
コード例 #2
0
ファイル: db_extension.go プロジェクト: pavanka/gorocksext
// NewIterators returns an array of iterators
// corresponding to the given column families for a given db
// iterators is allocated by this method -> responsibility of
// caller to destroy the underlying c objects
// opts, db, cfs will not be destroyed -> resonsibility of caller
func NewIterators(
	opts *gorocksdb.ReadOptions,
	db *gorocksdb.DB,
	cfHandles []*gorocksdb.ColumnFamilyHandle,
) ([]*gorocksdb.Iterator, error) {
	size := len(cfHandles)
	cCFHandles := make([]*C.rocksdb_column_family_handle_t, size, size)
	for i, cfHandle := range cfHandles {
		cCFHandles[i] = (*C.rocksdb_column_family_handle_t)(cfHandle.UnsafeGetCFHandler())
	}

	iters := make([]*C.rocksdb_iterator_t, size, size)
	var cErr *C.char
	C.get_iterators(
		(*C.rocksdb_readoptions_t)(opts.UnsafeGetReadOptions()),
		(*C.rocksdb_t)(db.UnsafeGetDB()),
		&cCFHandles[0],
		&iters[0],
		C.int(size),
		&cErr,
	)
	if cErr != nil {
		defer C.free(unsafe.Pointer(cErr))
		return nil, errors.New(C.GoString(cErr))
	}

	var iterators []*gorocksdb.Iterator
	for _, iter := range iters {
		iterators = append(
			iterators,
			gorocksdb.NewNativeIterator(unsafe.Pointer(iter)),
		)
	}
	return iterators, nil
}
コード例 #3
0
ファイル: db_extension.go プロジェクト: pavanka/gorocksext
// CreateCheckpoint creates an openable snapshot of the db
// db is not destroyed -> responsibility of the caller
func CreateCheckpoint(db *gorocksdb.DB, checkpointDir string) error {
	cCheckpointDir := C.CString(checkpointDir)
	defer C.free(unsafe.Pointer(cCheckpointDir))
	var cErr *C.char
	C.create_checkpoint(
		(*C.rocksdb_t)(db.UnsafeGetDB()),
		cCheckpointDir,
		&cErr,
	)
	if cErr != nil {
		defer C.free(unsafe.Pointer(cErr))
		return errors.New(C.GoString(cErr))
	}
	return nil
}
コード例 #4
0
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()

	createDBEntry := func(key 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
		}
	}
	go func() {
		for i, key := range filenames {
			createDBEntry(key)
		}
		close(putStatCh)
	}()
	return putStatCh
}