Esempio n. 1
0
// call KVAutobus keyvalue_range API and covert to slice of storage.KeyValue
func (db *KVAutobus) getRange(kStart, kEnd storage.Key) ([]*storage.KeyValue, error) {
	mkvs, err := db.getKVRange(kStart, kEnd)
	if err != nil {
		return nil, err
	}
	kvs := make([]*storage.KeyValue, len(mkvs))
	for i, mkv := range mkvs {
		kvs[i] = &storage.KeyValue{storage.Key(mkv[0]), []byte(mkv[1])}
	}
	return kvs, nil
}
Esempio n. 2
0
// RawRangeQuery sends a range of full keys.  This is to be used for low-level data
// retrieval like DVID-to-DVID communication and should not be used by data type
// implementations if possible.  A nil is sent down the channel when the
// range is complete.
func (db *KVAutobus) RawRangeQuery(kStart, kEnd storage.Key, keysOnly bool, out chan *storage.KeyValue, cancel <-chan struct{}) error {
	var value []byte
	if keysOnly {
		keys, err := db.getKeyRange(kStart, kEnd)
		if err != nil {
			return err
		}
		for _, key := range keys {
			out <- &storage.KeyValue{storage.Key(key), value}
		}
	} else {
		kvs, err := db.getKVRange(nil, kStart, kEnd)
		if err != nil {
			return err
		}
		for _, kv := range kvs {
			out <- &storage.KeyValue{storage.Key(kv[0]), []byte(kv[1])}
		}
	}
	return nil
}
Esempio n. 3
0
func TestTileKey(t *testing.T) {
	datastore.OpenTest()
	defer datastore.CloseTest()

	uuid, _ := initTestRepo()
	server.CreateTestInstance(t, uuid, "imagetile", "tiles", dvid.Config{})

	keyURL := fmt.Sprintf("%snode/%s/tiles/tilekey/xy/0/1_2_3", server.WebAPIPath, uuid)
	respStr := server.TestHTTP(t, "GET", keyURL, nil)
	keyResp := struct {
		Key string `json:"key"`
	}{}
	if err := json.Unmarshal(respStr, &keyResp); err != nil {
		t.Fatalf("Couldn't parse JSON response to tilekey request (%v):\n%s\n", err, keyResp)
	}
	kb := make([]byte, hex.DecodedLen(len(keyResp.Key)))
	_, err := hex.Decode(kb, []byte(keyResp.Key))
	if err != nil {
		t.Fatalf("Couldn't parse return hex key: %s", keyResp.Key)
	}

	// Decipher TKey portion to make sure it's correct.
	key := storage.Key(kb)
	tk, err := storage.TKeyFromKey(key)
	if err != nil {
		t.Fatalf("Couldn't get TKey from returned key (%v): %x", err, kb)
	}
	tile, plane, scale, err := DecodeTKey(tk)
	if err != nil {
		t.Fatalf("Bad decode of TKey (%v): %x", err, tk)
	}
	expectTile := dvid.ChunkPoint3d{1, 2, 3}
	if tile != expectTile {
		t.Errorf("Expected tile %v, got %v\n", expectTile, tile)
	}
	if !plane.Equals(dvid.XY) {
		t.Errorf("Expected plane to be XY, got %v\n", plane)
	}
	if scale != 0 {
		t.Errorf("Expected scale to be 0, got %d\n", scale)
	}
}
Esempio n. 4
0
func removeType(key storage.TKey) storage.Key {

	return storage.Key(key)
}