Ejemplo n.º 1
0
func BenchmarkBitcaskCurrency(b *testing.B) {
	storagePath := "benchMarkBitcask"
	os.RemoveAll(storagePath)
	opts := &Options{
		MaxFileSize: 1 << 12,
	}
	bc, err := Open(storagePath, opts)
	if err != nil {
		logger.Fatal(err)
	}

	keyValues := make(map[int]string)

	for i := 0; i < b.N/2; i++ {
		key := strconv.Itoa(i)
		value := strconv.Itoa(int(time.Now().Unix()))
		bc.Put([]byte(key), []byte(value))
		keyValues[i] = value
	}
	logger.Warn(b.N)
	logger.Info("Put all Data")
	for i := 0; i < b.N/2; i++ {
		k := strconv.Itoa(i)
		v, _ := bc.Get([]byte(k))
		if string(v) != keyValues[i] {
			logger.Error(string(v), keyValues[i])
			os.Exit(-1)
		}
	}
	logger.Info("Get all data")
	// delete all data
	for i := 0; i < b.N/2; i++ {
		k := strconv.Itoa(i)
		//v, _ := bc.Get([]byte(k))
		err := bc.Del([]byte(k))
		if err != nil {
			logger.Error(err)
		}
	}
	logger.Info("Delete all data")
	// Get all data
	for i := 0; i < b.N/2; i++ {
		k := strconv.Itoa(i)
		v, err := bc.Get([]byte(k))
		if err != ErrNotFound {
			logger.Error(string(v), keyValues[i])
		}
	}
	logger.Info("all data is not found, pass test")
	//mergeWorker.Staop()
	bc.Close()
}
Ejemplo n.º 2
0
// Get ...
func (bc *BitCask) Get(key []byte) ([]byte, error) {
	e := keyDirs.get(string(key))
	if e == nil {
		return nil, ErrNotFound
	}

	fileID := e.fileID
	bf, err := bc.getFileState(fileID)
	if err != nil && os.IsNotExist(err) {
		logger.Warn("key:", string(key), "=>the file is not exits:", fileID)
		//time.Sleep(time.Second)
		return nil, err
	}

	//TODO
	// assrt file crc32
	//logger.Info("fileID", fileID, "entry offset:", e.valueOffset, "\t entryLen:", e.valueSz)
	return bf.read(e.valueOffset, e.valueSz)
}