From b640631dafefe4f03f6ce2f9fe723e262cf366e4 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Thu, 11 May 2017 17:26:19 -0400 Subject: [PATCH] Apply remote metadata in _handle_sync_response We've already got it in the response, may as well apply it now rather than wait for the other end to get around to running its replicators. Change-Id: Ie36a6dd075beda04b9726dfa2bba9ffed025c9ef --- swift/common/db_replicator.py | 2 ++ test/probe/test_db_replicator.py | 13 +++---------- test/unit/common/test_db_replicator.py | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/swift/common/db_replicator.py b/swift/common/db_replicator.py index e25ac9124a..ebc77bf610 100644 --- a/swift/common/db_replicator.py +++ b/swift/common/db_replicator.py @@ -446,6 +446,8 @@ class Replicator(Daemon): elif 200 <= response.status < 300: rinfo = json.loads(response.data) local_sync = broker.get_sync(rinfo['id'], incoming=False) + if rinfo.get('metadata', ''): + broker.update_metadata(json.loads(rinfo['metadata'])) if self._in_sync(rinfo, info, broker, local_sync): return True # if the difference in rowids between the two differs by diff --git a/test/probe/test_db_replicator.py b/test/probe/test_db_replicator.py index 0a71a882eb..5ba39a8657 100755 --- a/test/probe/test_db_replicator.py +++ b/test/probe/test_db_replicator.py @@ -90,12 +90,13 @@ class TestDbUsyncReplicator(ReplProbeTest): expected_meta = { 'x-container-meta-a': '2', - 'x-container-meta-b': '2', + 'x-container-meta-b': '3', 'x-container-meta-c': '1', 'x-container-meta-d': '2', + 'x-container-meta-e': '3', } - # node that got the object updates still doesn't have the meta + # node that got the object updates now has the meta resp_headers = direct_client.direct_head_container( cnode, cpart, self.account, container) for header, value in expected_meta.items(): @@ -104,14 +105,6 @@ class TestDbUsyncReplicator(ReplProbeTest): self.assertNotIn(resp_headers.get('x-container-object-count'), (None, '0', 0)) - expected_meta = { - 'x-container-meta-a': '2', - 'x-container-meta-b': '3', - 'x-container-meta-c': '1', - 'x-container-meta-d': '2', - 'x-container-meta-e': '3', - } - # other nodes still have the meta, as well as objects for node in cnodes: resp_headers = direct_client.direct_head_container( diff --git a/test/unit/common/test_db_replicator.py b/test/unit/common/test_db_replicator.py index 66a07ac1e1..c62f1b8610 100644 --- a/test/unit/common/test_db_replicator.py +++ b/test/unit/common/test_db_replicator.py @@ -1503,7 +1503,9 @@ class TestReplToNode(unittest.TestCase): self.assertEqual(self.replicator._repl_to_node( self.fake_node, self.broker, '0', self.fake_info), True) metadata = self.broker.metadata - self.assertEqual({}, metadata) + self.assertIn("X-Container-Sysmeta-Test", metadata) + self.assertEqual("XYZ", metadata["X-Container-Sysmeta-Test"][0]) + self.assertEqual(now, metadata["X-Container-Sysmeta-Test"][1]) def test_repl_to_node_not_found(self): self.http = ReplHttp('{"id": 3, "point": -1}', set_status=404)