Skip to content

Commit

Permalink
move dataUUID migration to repo load; improve sync JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
DocSavage committed Jul 18, 2016
1 parent 4b6e5e2 commit 38e6c50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 14 additions & 4 deletions datastore/datainstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ func (d *Data) SyncedNames() []dvid.InstanceName {
// ---------------------------------------

func (d *Data) MarshalJSON() ([]byte, error) {
// convert sync UUIDs to names so its more understandable.
syncs := []dvid.InstanceName{}
for uuid := range d.syncData {
synced, err := GetDataByDataUUID(uuid)
if err != nil {
syncs = append(syncs, "undefined")
dvid.Errorf("In data %q found synced data UUID %q that cannot be found: %v\n", d.DataName(), uuid, err)
} else {
syncs = append(syncs, synced.DataName())
}
}
return json.Marshal(struct {
TypeName dvid.TypeString
TypeURL dvid.URLString
Expand All @@ -267,7 +278,7 @@ func (d *Data) MarshalJSON() ([]byte, error) {
RepoUUID dvid.UUID
Compression string
Checksum string
Syncs dvid.UUIDSet
Syncs []dvid.InstanceName
Versioned bool
}{
TypeName: d.typename,
Expand All @@ -278,7 +289,7 @@ func (d *Data) MarshalJSON() ([]byte, error) {
RepoUUID: d.rootUUID,
Compression: d.compression.String(),
Checksum: d.checksum.String(),
Syncs: d.syncData,
Syncs: syncs,
Versioned: !d.unversioned,
})
}
Expand Down Expand Up @@ -427,8 +438,7 @@ func (d *Data) GobDecode(b []byte) error {
dvid.Infof("Data %q had no explicit versioning flag: assume it's versioned.\n", d.name)
}
if err := dec.Decode(&(d.dataUUID)); err != nil {
d.dataUUID = dvid.NewUUID()
dvid.Infof("Data %q had no data UUID so assigning new UUID: %s\n", d.name, d.dataUUID)
dvid.Infof("Data %q had no data UUID.\n", d.name)
}
if err := dec.Decode(&(d.syncData)); err != nil {
if len(d.syncNames) != 0 {
Expand Down
11 changes: 10 additions & 1 deletion datastore/repo_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ func (m *repoManager) loadVersion0() error {

// Populate the instance id -> dataservice map and convert any deprecated data instance.
for dataname, dataservice := range r.data {
dataUUID := dataservice.DataUUID()
if dataUUID == "" {
dataUUID = dvid.NewUUID()
dataservice.SetDataUUID(dataUUID)
dvid.Infof("Assigned data %q to data UUID %s.\n", dataname, dataservice.DataUUID())
saveRepo = true
}
migrator, doMigrate := dataservice.(TypeMigrator)
if doMigrate {
dvid.Infof("Migrating instance %q of type %q to ...\n", dataservice.DataName(), dataservice.TypeName())
Expand Down Expand Up @@ -449,7 +456,7 @@ func (m *repoManager) loadVersion0() error {
if len(syncNames) == 0 {
continue
}
dvid.Infof("Converting %d legacy sync names to data UUIDs...\n", len(syncNames))
dvid.Infof("Converting data %q %d legacy sync names to data UUIDs...\n", dataservice.DataName(), len(syncNames))
syncs := dvid.UUIDSet{}
for _, name := range syncNames {
// get the dataservice associated with this synced data.
Expand All @@ -463,7 +470,9 @@ func (m *repoManager) loadVersion0() error {
dvid.Errorf(" Skipping sync of %q with missing data %q for repo @ %s", dataservice.DataName(), name, r.uuid)
}
}
dvid.Infof("After conversion data %q has syncs: %v\n", dataservice.DataName(), syncs)
dataservice.SetSync(syncs)
dvid.Infof("After calling SetSync we get back: %v\n", syncer.SyncedData())
saveRepo = true
}
}
Expand Down

0 comments on commit 38e6c50

Please sign in to comment.