Shared content across namespaces
Update content ingests to use content from another namespace. Ingests must be committed to make content available and the client will see the sharing as an ingest which has already been fully written to, but not completed. Updated the database version to change the ingest record in the database from a link key to an object with a link and expected value. This expected value is used to indicate that the content already exists and an underlying writer may not yet exist. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -24,6 +24,11 @@ var migrations = []migration{
|
||||
version: 1,
|
||||
migrate: addChildLinks,
|
||||
},
|
||||
{
|
||||
schema: "v1",
|
||||
version: 2,
|
||||
migrate: migrateIngests,
|
||||
},
|
||||
}
|
||||
|
||||
// addChildLinks Adds children key to the snapshotters to enforce snapshot
|
||||
@@ -83,3 +88,53 @@ func addChildLinks(tx *bolt.Tx) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// migrateIngests moves ingests from the key/value ingest bucket
|
||||
// to a structured ingest bucket for storing additional state about
|
||||
// an ingest.
|
||||
func migrateIngests(tx *bolt.Tx) error {
|
||||
v1bkt := tx.Bucket(bucketKeyVersion)
|
||||
if v1bkt == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// iterate through each namespace
|
||||
v1c := v1bkt.Cursor()
|
||||
|
||||
for k, v := v1c.First(); k != nil; k, v = v1c.Next() {
|
||||
if v != nil {
|
||||
continue
|
||||
}
|
||||
bkt := v1bkt.Bucket(k).Bucket(bucketKeyObjectContent)
|
||||
if bkt == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
dbkt := bkt.Bucket(deprecatedBucketKeyObjectIngest)
|
||||
if dbkt == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Create new ingests bucket
|
||||
nbkt, err := bkt.CreateBucketIfNotExists(bucketKeyObjectIngests)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := dbkt.ForEach(func(ref, bref []byte) error {
|
||||
ibkt, err := nbkt.CreateBucketIfNotExists(ref)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ibkt.Put(bucketKeyRef, bref)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := bkt.DeleteBucket(deprecatedBucketKeyObjectIngest); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user