From 2a4e3b9ca03e5d751ce51549408c774e71defcb6 Mon Sep 17 00:00:00 2001
From: Milind Changire <mchangir@redhat.com>
Date: Fri, 3 Jul 2015 12:02:11 +0530
Subject: [PATCH 202/212] tools/glusterfind: RENAME and MODIFY issues
If Modification happens before RENAME, GFID to Path Conversion
converts it into New Path. Delete Modify Entry and insert again
So that MODIFY <NEW NAME> comes after RENAME.
Default value of pgfids and basenames changed to "" instead of NULL
Also fixed RENAME issue of displaying "RENAME <NEW NAME> <NEW NAME>".
Also fixed RENAME followed by missing MODIFY
Change-Id: Ie67219cc049a427e95ab6426bb890b02ffc1a853
BUG: 1228247
Reviewed-On: http://review.gluster.org/#/c/11443/
Signed-off-by: Milind Changire <mchangir@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/52285
Reviewed-by: Kotresh Hiremath Ravishankar <khiremat@redhat.com>
Reviewed-by: Venky Shankar <vshankar@redhat.com>
Tested-by: Venky Shankar <vshankar@redhat.com>
---
tools/glusterfind/src/changelogdata.py | 39 +++++++++++++++++++++++---------
tools/glusterfind/src/main.py | 3 +-
2 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/tools/glusterfind/src/changelogdata.py b/tools/glusterfind/src/changelogdata.py
index c42aa2a..08d711b 100644
--- a/tools/glusterfind/src/changelogdata.py
+++ b/tools/glusterfind/src/changelogdata.py
@@ -100,10 +100,10 @@ class ChangelogData(object):
ts VARCHAR,
type VARCHAR,
gfid VARCHAR(40),
- pgfid1 VARCHAR(40),
- bn1 VARCHAR(500),
- pgfid2 VARCHAR(40),
- bn2 VARCHAR(500),
+ pgfid1 VARCHAR(40) DEFAULT '',
+ bn1 VARCHAR(500) DEFAULT '',
+ pgfid2 VARCHAR(40) DEFAULT '',
+ bn2 VARCHAR(500) DEFAULT '',
path1 VARCHAR DEFAULT '',
path2 VARCHAR DEFAULT ''
)
@@ -283,7 +283,7 @@ class ChangelogData(object):
def append_path1(self, path, inode):
# || is for concatenate in SQL
- query = """UPDATE gfidpath SET path1 = ',' || ?
+ query = """UPDATE gfidpath SET path1 = path1 || ',' || ?
WHERE gfid IN (SELECT gfid FROM inodegfid WHERE inode = ?)"""
self.cursor.execute(query, (path, inode))
@@ -344,16 +344,32 @@ class ChangelogData(object):
"pgfid1": pgfid1, "bn1": bn1})
elif self.gfidpath_exists({"gfid": data[1], "type": "RENAME",
"pgfid2": pgfid1, "bn2": bn1}):
- # If <OLD_PGFID>/<BNAME> is same as <PGFID2>/<BN2>(may be previous
- # RENAME) then UPDATE <NEW_PGFID>/<BNAME> as <PGFID2>/<BN2>
- self.gfidpath_update({"pgfid2": pgfid2, "bn2": bn2},
- {"gfid": data[1], "type": "RENAME",
- "pgfid2": pgfid1, "bn2": bn1})
+ # If we are renaming file back to original name then just
+ # delete the entry since it will effectively be a no-op
+ if self.gfidpath_exists({"gfid": data[1], "type": "RENAME",
+ "pgfid2": pgfid1, "bn2": bn1,
+ "pgfid1": pgfid2, "bn1": bn2}):
+ self.gfidpath_delete({"gfid": data[1], "type": "RENAME",
+ "pgfid2": pgfid1, "bn2": bn1})
+ else:
+ # If <OLD_PGFID>/<BNAME> is same as <PGFID2>/<BN2>
+ # (may be previous RENAME)
+ # then UPDATE <NEW_PGFID>/<BNAME> as <PGFID2>/<BN2>
+ self.gfidpath_update({"pgfid2": pgfid2, "bn2": bn2},
+ {"gfid": data[1], "type": "RENAME",
+ "pgfid2": pgfid1, "bn2": bn1})
else:
# Else insert as RENAME
self.gfidpath_add(changelogfile, RecordType.RENAME, data[1],
pgfid1, bn1, pgfid2, bn2)
+ if self.gfidpath_exists({"gfid": data[1], "type": "MODIFY"}):
+ # If MODIFY exists already for that GFID, remove it and insert
+ # again so that MODIFY entry comes after RENAME entry
+ # Output will have MODIFY <NEWNAME>
+ self.gfidpath_delete({"gfid": data[1], "type": "MODIFY"})
+ self.gfidpath_add(changelogfile, RecordType.MODIFY, data[1])
+
def when_link_symlink(self, changelogfile, data):
# E <GFID> <LINK|SYMLINK> <PGFID>/<BASENAME>
# Add as New record in Db as Type NEW
@@ -366,7 +382,8 @@ class ChangelogData(object):
def when_data_meta(self, changelogfile, data):
# If GFID row exists, Ignore else Add to Db
- if not self.gfidpath_exists({"gfid": data[1]}):
+ if not self.gfidpath_exists({"gfid": data[1], "type": "NEW"}) and \
+ not self.gfidpath_exists({"gfid": data[1], "type": "MODIFY"}):
self.gfidpath_add(changelogfile, RecordType.MODIFY, data[1])
def when_unlink_rmdir(self, changelogfile, data):
diff --git a/tools/glusterfind/src/main.py b/tools/glusterfind/src/main.py
index 8d32295..9a6a2ac 100644
--- a/tools/glusterfind/src/main.py
+++ b/tools/glusterfind/src/main.py
@@ -433,7 +433,8 @@ def mode_pre(session_dir, args):
# Multiple paths in case of Hardlinks
paths = row[1].split(",")
for p in paths:
- if p == "":
+ if p == "" or p.replace("%2F%2F","%2F") == \
+ row[2].replace("%2F%2F","%2F"):
continue
f.write("%s %s %s\n" % (row[0], p, row[2]))
--
1.7.1