コード例 #1
0
func (st StorageS3) Download(saveDirPath string) *switchDB {
	//save into temp file
	os.MkdirAll(saveDirPath, 0700)
	dirname := uuid.NewUUID().String()
	dirpath := path.Join(saveDirPath, dirname)
	tarpath := dirpath + ".tar"
	err := st.client.DownloadObject(st.Bucket, st.Path, tarpath)
	if err != nil {
		glog.Warning("download ", st.Path, " has failed")
		return nil
	}
	// unfolding
	err = unfoldTar(tarpath, dirpath)
	if err != nil {
		glog.Info("unforlding ", st.Path, " has failed")
		return nil
	}
	os.RemoveAll(tarpath)
	db, err := leveldb.OpenFile(dirpath, nil)
	if err != nil {
		glog.Info("opening ", st.Path, " has failed")
		return nil
	}
	glog.Info("download ", st.Path, " done")
	return &switchDB{db, dirpath}
}
コード例 #2
0
func BenchmarkRead10000CachedData(b *testing.B) {
	os.MkdirAll(testdbpath, 0700)
	dirname := uuid.NewUUID().String()
	dbpath := path.Join(testdbpath, dirname)

	makeDB(dbpath, 10000)
	db, _ := leveldb.OpenFile(dbpath, nil)

	conf := LevelDBConf{"test", testdbpath, nil, nil}

	ldb := NewLevelDBWithDB(db, dbpath, conf)
	go ldb.run()
	defer func() {
		ldb.Close()
	}()

	for i := 1; i <= 10000; i++ {
		key := fmt.Sprintf("testdata:%d", i)
		ldb.Get(key, UnmarshalTestStruct)
	}

	b.ResetTimer()

	for i := 1; i <= 10000; i++ {
		key := fmt.Sprintf("testdata:%d", i)
		ldb.Get(key, UnmarshalTestStruct)
	}
}