예제 #1
0
func (m *repoManager) newInstanceID() (dvid.InstanceID, error) {
	m.idMutex.Lock()
	defer m.idMutex.Unlock()

	// Generate a new instance ID based on the method in configuration.
	var err error
	var curid dvid.InstanceID
	invalidID := true
	for invalidID {
		switch m.instanceIDGen {
		case "sequential":
			curid = m.instanceID
			m.instanceID++
			err = m.putNewIDs()
		case "random":
			s1 := rand.NewSource(time.Now().UnixNano())
			r1 := rand.New(s1)
			curid = dvid.InstanceID(r1.Uint32())
		}
		_, found := m.iids[curid]
		if !found {
			invalidID = false
		}
	}
	return curid, err
}
예제 #2
0
func TestDataGobEncoding(t *testing.T) {
	compression, _ := dvid.NewCompression(dvid.LZ4, dvid.DefaultCompression)
	data := &TestData{&Data{
		typename:    "testtype",
		typeurl:     "foo.bar.baz/testtype",
		typeversion: "1.0",
		id:          dvid.InstanceID(13),
		name:        "my fabulous data",
		rootUUID:    dvid.UUID("42"),
		dataUUID:    dvid.NewUUID(),
		compression: compression,
		checksum:    dvid.DefaultChecksum,
		syncData:    dvid.UUIDSet{"moo": struct{}{}, "bar": struct{}{}, "baz": struct{}{}},
	}}

	encoding, err := data.GobEncode()
	if err != nil {
		t.Fatalf("Couldn't Gob encode test data: %v\n", err)
	}
	data2 := &TestData{new(Data)}
	if err = data2.GobDecode(encoding); err != nil {
		t.Fatalf("Couldn't Gob decode test data: %v\n", err)
	}
	if !reflect.DeepEqual(data, data2) {
		t.Errorf("Bad Gob roundtrip:\nOriginal: %v\nReturned: %v\n", data, data2)
	}
}
예제 #3
0
func LoadConfig(filename string) (*datastore.InstanceConfig, *dvid.LogConfig, *dvid.StoreConfig, error) {
	if filename == "" {
		return nil, nil, nil, fmt.Errorf("No server TOML configuration file provided")
	}
	if _, err := toml.DecodeFile(filename, &tc); err != nil {
		return nil, nil, nil, fmt.Errorf("Could not decode TOML config: %v\n", err)
	}

	// The server config could be local, cluster, gcloud-specific config.  Here it is local.
	config = &tc
	ic := datastore.InstanceConfig{tc.Server.IIDGen, dvid.InstanceID(tc.Server.IIDStart)}
	return &ic, &(tc.Logging), &(tc.Store), nil
}
예제 #4
0
func TestBasicGraph(t *testing.T) {
	tests.UseStore()
	defer tests.CloseStore()

	graphDB, err := storage.GraphStore()
	if err != nil {
		t.Fatalf("Can't open graph store: %v\n", err)
	}

	ctx := storage.GetTestDataContext(storage.TestUUID1, "graph", dvid.InstanceID(13))

	if err = graphDB.CreateGraph(ctx); err != nil {
		t.Errorf("Can't create graph: %v\n", err)
	}

	if err = graphDB.AddVertex(ctx, 1, 5); err != nil {
		t.Errorf("Can't add vertex: %v\n", err)
	}

	if err = graphDB.AddVertex(ctx, 2, 11); err != nil {
		t.Errorf("Can't add vertex: %v\n", err)
	}

	if err = graphDB.AddEdge(ctx, 1, 2, 0.3); err != nil {
		t.Errorf("Can't add edge: %v\n", err)
	}

	vert1, err := graphDB.GetVertex(ctx, 1)
	if err != nil {
		t.Errorf("Can't get vertex: %v\n", err)
	}
	if vert1.Weight != float64(5) {
		t.Errorf("Bad weight.  Should be %f, was %f\n", 5, vert1.Weight)
	}

	vert2, err := graphDB.GetVertex(ctx, 2)
	if err != nil {
		t.Errorf("Can't get vertex: %v\n", err)
	}
	if vert2.Weight != float64(11) {
		t.Errorf("Bad weight.  Should be %f, was %f\n", 11, vert1.Weight)
	}

	edge, err := graphDB.GetEdge(ctx, 1, 2)
	if err != nil {
		t.Errorf("Can't get edge: %v\n", err)
	}
	if edge.Weight != float64(0.3) {
		t.Errorf("Bad edge.  Should be %f, was %f\n", 0.3, edge.Weight)
	}

	edge, err = graphDB.GetEdge(ctx, 2, 1)
	if err != nil {
		t.Errorf("Can't get edge: %v\n", err)
	}
	if edge.Weight != float64(0.3) {
		t.Errorf("Bad edge.  Should be %f, was %f\n", 0.3, edge.Weight)
	}

	if err = graphDB.RemoveGraph(ctx); err != nil {
		t.Errorf("Error removing graph: %v\n", err)
	}
}
예제 #5
0
// LoadConfig loads DVID server configuration from a TOML file.
func LoadConfig(filename string) (*datastore.InstanceConfig, *dvid.LogConfig, *storage.Backend, error) {
	if filename == "" {
		return nil, nil, nil, fmt.Errorf("No server TOML configuration file provided")
	}
	if _, err := toml.DecodeFile(filename, &tc); err != nil {
		return nil, nil, nil, fmt.Errorf("Could not decode TOML config: %v\n", err)
	}

	// Get all defined stores.
	backend := new(storage.Backend)
	backend.Groupcache = tc.Groupcache
	var err error
	backend.Stores, err = tc.Stores()
	if err != nil {
		return nil, nil, nil, err
	}

	// Get default store if there's only one store defined.
	if len(backend.Stores) == 1 {
		for k := range backend.Stores {
			backend.Default = storage.Alias(strings.Trim(string(k), "\""))
		}
	}

	// Create the backend mapping.
	backend.Mapping = make(map[dvid.DataSpecifier]storage.Alias)
	for k, v := range tc.Backend {
		// lookup store config
		_, found := backend.Stores[v.Store]
		if !found {
			return nil, nil, nil, fmt.Errorf("Backend for %q specifies unknown store %q", k, v.Store)
		}
		spec := dvid.DataSpecifier(strings.Trim(string(k), "\""))
		backend.Mapping[spec] = v.Store
	}
	defaultAlias, found := backend.Mapping["default"]
	if found {
		backend.Default = defaultAlias
	} else {
		if backend.Default == "" {
			return nil, nil, nil, fmt.Errorf("if no default backend specified, must have exactly one store defined in config file")
		}
	}
	defaultMetadataName, found := backend.Mapping["metadata"]
	if found {
		backend.Metadata = defaultMetadataName
	} else {
		if backend.Default == "" {
			return nil, nil, nil, fmt.Errorf("can't set metadata if no default backend specified, must have exactly one store defined in config file")
		}
		backend.Metadata = backend.Default
	}

	// The server config could be local, cluster, gcloud-specific config.  Here it is local.
	config = &tc
	ic := datastore.InstanceConfig{
		Gen:   tc.Server.IIDGen,
		Start: dvid.InstanceID(tc.Server.IIDStart),
	}
	return &ic, &(tc.Logging), backend, nil
}