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) } }
// Returns an RPC "socket" that can push data to remote. func NewPushSocket(target string) (*rpcSocket, error) { client, err := rpc.DialHTTP("tcp", target) if err != nil { return nil, fmt.Errorf("Could not find DVID server to message at %s [%v]\n", target, err) } msg := Message{Session: string(dvid.NewUUID())} return &rpcSocket{target, client, msg}, nil }
func GetTestDataContext(uuid dvid.UUID, name string, instanceID dvid.InstanceID) *DataContext { versionID, found := testUUIDToVersion[uuid] if !found { return nil } data := &testData{ dataUUID: dvid.NewUUID(), rootUUID: uuid, name: dvid.InstanceName(name), instanceID: instanceID, } return NewDataContext(data, versionID) }
// newUUID a local VersionID for either a provided UUID or if none is a provided, an // automatically generated one. func (m *repoManager) newUUID(assign *dvid.UUID) (dvid.UUID, dvid.VersionID, error) { m.idMutex.Lock() defer m.idMutex.Unlock() var uuid dvid.UUID if assign == nil { uuid = dvid.NewUUID() } else { uuid = *assign } curid := m.versionID m.versionToUUID[curid] = uuid m.uuidToVersion[uuid] = curid m.versionID++ if err := m.putCaches(); err != nil { return uuid, curid, err } return uuid, curid, m.putNewIDs() }
// NewDataService returns a new Data instance that fulfills the DataService interface. // The UUID passed in corresponds to the root UUID of the DAG subgraph that should hold the data. // This returned Data struct is usually embedded by datatype-specific data instances. // By default, LZ4 and the default checksum is used. func NewDataService(t TypeService, rootUUID dvid.UUID, id dvid.InstanceID, name dvid.InstanceName, c dvid.Config) (*Data, error) { if _, reserved := reservedNames[string(name)]; reserved { return nil, fmt.Errorf("cannot use reserved name %q", name) } // // Don't allow identical names to be used in the same repo. // d, err := GetDataByUUIDName(rootUUID, name) // if err == nil && d != nil { // return nil, fmt.Errorf("cannot create data instance %q when one already exists in repo with UUID %s", name, rootUUID) // } // See if a store was defined for a particular data instance. store, err := storage.GetAssignedStore(name, rootUUID, t.GetTypeName()) if err != nil { return nil, err } // Make sure we generate a valid UUID for the data instance. dataUUID := dvid.NewUUID() if dataUUID == dvid.NilUUID { return nil, fmt.Errorf("Unable to generate new UUID for data %q creation", name) } // Setup the basic data instance structure. compression, _ := dvid.NewCompression(dvid.LZ4, dvid.DefaultCompression) data := &Data{ typename: t.GetTypeName(), typeurl: t.GetTypeURL(), typeversion: t.GetTypeVersion(), dataUUID: dataUUID, id: id, name: name, rootUUID: rootUUID, compression: compression, checksum: dvid.DefaultChecksum, syncNames: []dvid.InstanceName{}, syncData: dvid.UUIDSet{}, unversioned: false, store: store, } return data, data.ModifyConfig(c) }