Skip to content

Commit

Permalink
MB-23914: The server version for each node should be persisted during…
Browse files Browse the repository at this point in the history
… backup

We can use the server version to determine various restrictions that
we need to be aware of when backuping up different versions of
Couchbase. In particular the addition of xattrs in Couchbase 5.0
means that we need to make sure that the next backup we do is a
full backup. If a backup doesn't have a version number we set the
version number to 0.0.0 and assume that the backup was taken against
a pre-5.0 Couchbase cluster.

Change-Id: I1dd9e90cafd51dacdcd734fee38c9356360784be
Reviewed-on: http://review.couchbase.org/77415
Reviewed-by: Eben Haber <eben@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information
mikewied authored and Michael Wiederhold committed Apr 28, 2017
1 parent e88fb70 commit 84e5ece
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion pump_bfd.py
Expand Up @@ -67,6 +67,18 @@ def get_predecessors(parent_dir):
except IOError:
return []

@staticmethod
def get_server_version(parent_dir):
try:
json_file = open(os.path.join(parent_dir, "meta.json"), "r")
json_data = json.load(json_file)
json_file.close()
if "version" in json_data:
return json_data["version"]
return "0.0.0"
except IOError:
return "0.0.0"

@staticmethod
def get_failover_log(parent_dir):
try:
Expand Down Expand Up @@ -226,13 +238,15 @@ def find_seqno(opts, spec, bucket_name, node_name, mode):
if not os.path.isdir(path):
return seqno, dep_list, failover_log, snapshot_markers

last_backup = BFD.construct_dir(fulldir, bucket_name, node_name)
file_list.extend(recursive_glob(path, 'data-*.cbb'))
failoverlog_list.extend(recursive_glob(path, 'failover.json'))
snapshot_list.extend(recursive_glob(path, 'snapshot_markers.json'))
seqno_list.extend(recursive_glob(path, 'seqno.json'))

accudir, accu_dirs = BFD.find_latest_dir(timedir, "accu")
if accudir:
last_backup = accudir
path = BFD.construct_dir(accudir, bucket_name, node_name)
if os.path.isdir(path):
file_list.extend(recursive_glob(path, 'data-*.cbb'))
Expand All @@ -242,6 +256,7 @@ def find_seqno(opts, spec, bucket_name, node_name, mode):
if mode.find("diff") >= 0:
diffdir, diff_dirs = BFD.find_latest_dir(timedir, "diff")
if diff_dirs:
last_backup = BFD.construct_dir(diffdir, bucket_name, node_name)
for dir in diff_dirs:
path = BFD.construct_dir(dir, bucket_name, node_name)
if os.path.isdir(path):
Expand All @@ -250,6 +265,9 @@ def find_seqno(opts, spec, bucket_name, node_name, mode):
snapshot_list.extend(recursive_glob(path, 'snapshot_markers.json'))
seqno_list.extend(recursive_glob(path, 'seqno.json'))

if BFD.get_server_version(last_backup) < "5.0.0":
return dict(), list(), dict(), dict()

for x in sorted(seqno_list):
try:
json_file = open(x, "r")
Expand Down Expand Up @@ -606,6 +624,13 @@ def run(self):
if "conflictResolutionType" in self.source_bucket:
confResType = self.source_bucket["conflictResolutionType"]

version = "0.0.0"
for bucket in self.source_map["buckets"]:
if self.bucket_name() == bucket["name"]:
for node in bucket["nodes"]:
if node["hostname"] == self.node_name():
version = node["version"].split("-")[0]

seqno_map = {}
for i in range(BFD.NUM_VBUCKET):
seqno_map[i] = 0
Expand All @@ -624,7 +649,9 @@ def run(self):

meta_file = os.path.join(db_dir, "meta.json")
json_file = open(meta_file, "w")
toWrite = {'pred': dep, 'conflict_resolution_type': confResType}
toWrite = {'pred': dep,
'conflict_resolution_type': confResType,
'version': version}
json.dump(toWrite, json_file, ensure_ascii=False)
json_file.close()

Expand Down

0 comments on commit 84e5ece

Please sign in to comment.