[ARVADOS] created: 0b9975ce9bb35c4a34d23f83bb8c4e7376fa1eb1
git at public.curoverse.com
git at public.curoverse.com
Tue Mar 3 18:01:09 EST 2015
at 0b9975ce9bb35c4a34d23f83bb8c4e7376fa1eb1 (commit)
commit 0b9975ce9bb35c4a34d23f83bb8c4e7376fa1eb1
Author: Brett Smith <brett at curoverse.com>
Date: Tue Mar 3 18:00:21 2015 -0500
5319: Add API migration for manifests with bad portable data hashes.
Refer to #5319 for background discussion and rationale. The migration
ensures that collections are still addressable by the bad
portable_data_hash, but the existing collection object has the correct
portable_data_hash.
diff --git a/services/api/db/migrate/20150303210106_fix_collection_portable_data_hash_with_hinted_manifest.rb b/services/api/db/migrate/20150303210106_fix_collection_portable_data_hash_with_hinted_manifest.rb
new file mode 100644
index 0000000..2a5570a
--- /dev/null
+++ b/services/api/db/migrate/20150303210106_fix_collection_portable_data_hash_with_hinted_manifest.rb
@@ -0,0 +1,57 @@
+class FixCollectionPortableDataHashWithHintedManifest < ActiveRecord::Migration
+ include CurrentApiClient
+
+ def each_bad_collection
+ Collection.find_each do |coll|
+ next unless (coll.manifest_text =~ /\+[B-Z]/)
+ stripped_manifest = coll.manifest_text.
+ gsub(/( [0-9a-f]{32}(\+\d+)?)(\+\S+)/, '\1')
+ stripped_pdh = sprintf("%s+%i",
+ Digest::MD5.hexdigest(stripped_manifest),
+ stripped_manifest.bytesize)
+ yield [coll, stripped_pdh] if (coll.portable_data_hash != stripped_pdh)
+ end
+ end
+
+ def up
+ copied_attr_names =
+ [:owner_uuid, :created_at, :modified_by_client_uuid,
+ :modified_by_user_uuid, :modified_at, :updated_at, :name,
+ :description, :portable_data_hash, :replication_desired,
+ :replication_confirmed, :replication_confirmed_at]
+ new_expiry = Date.new(2038, 1, 31)
+
+ act_as_system_user
+ each_bad_collection do |coll, stripped_pdh|
+ # Create a copy of the collection including bad portable data hash,
+ # with an expiration. This makes it possible to resolve the bad
+ # portable data hash, but the expiration can hide the Collection
+ # from more user-friendly interfaces like Workbench.
+ properties = coll.properties.dup
+ properties["migrated_from"] ||= coll.uuid
+ coll_copy = Collection.
+ create!(manifest_text: coll.manifest_text,
+ properties: properties,
+ expires_at: coll.expires_at || new_expiry)
+ # update_column skips validations and callbacks, which lets us
+ # set an "invalid" portable_data_hash and avoid messing with
+ # modification metadata.
+ copied_attr_names.each do |attr_sym|
+ coll_copy.update_column(attr_sym, coll.send(attr_sym))
+ end
+ coll.update_column(:portable_data_hash, stripped_pdh)
+ end
+ end
+
+ def down
+ act_as_system_user
+ each_bad_collection do |coll, stripped_pdh|
+ if ((src_uuid = coll.properties["migrated_from"]) and
+ (src_coll = Collection.where(uuid: src_uuid).first) and
+ (src_coll.portable_data_hash == stripped_pdh))
+ src_coll.update_column(:portable_data_hash, coll.portable_data_hash)
+ end
+ coll.delete
+ end
+ end
+end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index afc0351..007d05e 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -2360,4 +2360,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150206210804');
INSERT INTO schema_migrations (version) VALUES ('20150206230342');
-INSERT INTO schema_migrations (version) VALUES ('20150216193428');
\ No newline at end of file
+INSERT INTO schema_migrations (version) VALUES ('20150216193428');
+
+INSERT INTO schema_migrations (version) VALUES ('20150303210106');
\ No newline at end of file
commit e58abe5001fff1347d6a7fdc84b67e84cce47731
Author: Brett Smith <brett at curoverse.com>
Date: Tue Mar 3 17:36:24 2015 -0500
5319: Fix incorrect portable_data_hash in test fixture.
diff --git a/services/api/test/fixtures/collections.yml b/services/api/test/fixtures/collections.yml
index 2201225..d8c4c44 100644
--- a/services/api/test/fixtures/collections.yml
+++ b/services/api/test/fixtures/collections.yml
@@ -434,7 +434,7 @@ replication_desired_2_confirmed_2:
created_at: 2015-02-07 00:19:28.596506247 Z
modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
modified_at: 2015-02-07 00:19:28.596338465 Z
- portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
+ portable_data_hash: ec53808e4c23e6aeebea24d998ae5346+88
replication_desired: 2
replication_confirmed_at: 2015-02-07 00:24:52.983381227 Z
replication_confirmed: 2
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list