Add --checkpoint-period option to sync/clone
PATCH 1/1 Add --checkpoint-period option to sync/clone
Importing a long history from Perforce into git using the git-p4 tool can be especially challenging. The git p4 clone operation is based on an all-or-nothing transactionality guarantee. Under real-world conditions like network unreliability or a busy Perforce server, git p4 clone and git p4 sync operations can easily fail, forcing a user to restart the import process from the beginning. The longer the history being imported, the more likely a fault occurs during the process. Long enough imports thus become statistically unlikely to ever succeed.
I'm looking for feedback on a potential approach for addressing the problem. My idea was to leverage the checkpoint feature of git fast-import. I've included a patch which exposes a new option to the sync/clone commands in the git-p4 tool. The option enables explict checkpoints on a periodic basis (approximately every x seconds).
If the sync/clone command fails during processing of Perforce changes, the user can craft a new git p4 sync command that will identify changes that have already been imported and proceed with importing only changes more recent than the last successful checkpoint.
Assuming this approach makes sense, there are a few questions/items I have:
1. To add tests for this option, I'm thinking I'd need to simulate a Perforce server or client that exits abnormally after first processing some operations successfully. I'm looking for suggestions on sane approaches for implementing that.
2. From a usability perspective, I think it makes sense to print out a message upon clone/sync failure if the user has enabled the option. This message would describe how long ago the last successful checkpoint was completed and document what command/s to execute to continue importing Perforce changes. Ideally, the commmand to continue would be exactly the same as the command which failed, but today, clone will ignore any commits already imported to git. There are some lingering TODO comments in git-p4.py suggesting that clone should try to avoid reimporting changes. I don't mind taking a stab at addressing the TODO, but am worried I'll quickly encounter edge cases in the clone/sync features I don't understand.
3. This is my first attempt at a git contribution, so I'm definitely looking for feedback on commit messages, etc.
Cheers!
Ori Rawlings (1):
[git-p4.py] Add --checkpoint-period option to sync/clone
git-p4.py | 8 ++++++++ 1 file changed, 8 insertions(+)
Signature · 1 line
2.7.4 (Apple Git-66)
PATCH 1/1 Add --checkpoint-period option to sync/clone
Importing a long history from Perforce into git using the git-p4 tool can be especially challenging. The git p4 clone operation is based on an all-or-nothing transactionality guarantee. Under real-world conditions like network unreliability or a busy Perforce server, git p4 clone and git p4 sync operations can easily fail, forcing a user to restart the import process from the beginning. The longer the history being imported, the more likely a fault occurs during the process. Long enough imports thus become statistically unlikely to ever succeed.
The underlying git fast-import protocol supports an explicit checkpoint command. The idea here is to optionally allow the user to force an explicit checkpoint every <x> seconds. If the sync/clone operation fails branches are left updated at the appropriate commit available during the latest checkpoint. This allows a user to resume importing Perforce history while only having to repeat at most approximately <x> seconds worth of import activity.
--- git-p4.py | 8 ++++++++ 1 file changed, 8 insertions(+)
git-p4.py +8 -0
@@ -2244,6 +2244,7 @@ class P4Sync(Command, P4UserMap): optparse.make_option("-/", dest="cloneExclude", action="append", type="string", help="exclude depot path"), + optparse.make_option("--checkpoint-period", dest="checkpointPeriod", type="int", help="Period in seconds between explict git fast-import checkpoints (by default, no explicit checkpoints are performed)"), ] self.description = """Imports from Perforce into a git repository.\n example:
@@ -2276,6 +2277,7 @@ class P4Sync(Command, P4UserMap): self.tempBranches = [] self.tempBranchLocation = "refs/git-p4-tmp" self.largeFileSystem = None + self.checkpointPeriod = -1 if gitConfig('git-p4.largeFileSystem'): largeFileSystemConstructor = globals()[gitConfig('git-p4.largeFileSystem')]
@@ -3031,6 +3033,8 @@ class P4Sync(Command, P4UserMap): def importChanges(self, changes): cnt = 1 + if self.checkpointPeriod > -1: + self.lastCheckpointTime = time.time() for change in changes: description = p4_describe(change) self.updateOptionDict(description)
@@ -3107,6 +3111,10 @@ class P4Sync(Command, P4UserMap): self.initialParent) # only needed once, to connect to the previous commit self.initialParent = "" + + if self.checkpointPeriod > -1 and time.time() - self.lastCheckpointTime > self.checkpointPeriod: + self.checkpoint() + self.lastCheckpointTime = time.time() except IOError: print self.gitError.read() sys.exit(1)
Signature · 1 line
2.7.4 (Apple Git-66)
Quoted 9 lines · Ori Rawlings
Importing a long history from Perforce into git using the git-p4 tool can be especially challenging. The
git p4 cloneoperation is based on an all-or-nothing transactionality guarantee. Under real-world conditions like network unreliability or a busy Perforce server,git p4 cloneandgit p4 syncoperations can easily fail, forcing a user to restart the import process from the beginning. The longer the history being imported, the more likely a fault occurs during the process. Long enough imports thus become statistically unlikely to ever succeed.
That would never happen :-)
The usual thing that I find is that my Perforce login session expires.
Quoted 8 lines
The underlying git fast-import protocol supports an explicit checkpoint command. The idea here is to optionally allow the user to force an explicit checkpoint every <x> seconds. If the sync/clone operation fails branches are left updated at the appropriate commit available during the latest checkpoint. This allows a user to resume importing Perforce history while only having to repeat at most approximately <x> seconds worth of import activity.
I think this ought to work, and could be quite useful. It would be good to have some kind of test case for it though, and updated documentation.
Luke
Quoted 19 lines
Signed-off-by Ori Rawlings <[email protected]>--- git-p4.py | 8 ++++++++ 1 file changed, 8 insertions(+)git-p4.py +1
-0@@ -2244,6 +2244,7 @@ class P4Sync(Command, P4UserMap): optparse.make_option("-/", dest="cloneExclude", action="append", type="string", help="exclude depot path"), + optparse.make_option("--checkpoint-period", dest="checkpointPeriod", type="int", help="Period in seconds between explict git fast-import checkpoints (by default, no explicit checkpoints are performed)"), ] self.description = """Imports from Perforce into a git repository.\n example:
git-p4.py class P4Sync(Command, P4UserMap): · line 2280
Quoted 4 lines
git-p4.py +1
-0@@ -2276,6 +2277,7 @@ class P4Sync(Command, P4UserMap): self.tempBranches = [] self.tempBranchLocation = "refs/git-p4-tmp" self.largeFileSystem = None + self.checkpointPeriod = -1
Or use None?
git-p4.py class P4Sync(Command, P4UserMap): · line 3037
Quoted 9 lines
git-p4.py +2
-0if gitConfig('git-p4.largeFileSystem'): largeFileSystemConstructor = globals()[gitConfig('git-p4.largeFileSystem')]@@ -3031,6 +3033,8 @@ class P4Sync(Command, P4UserMap): def importChanges(self, changes): cnt = 1 + if self.checkpointPeriod > -1: + self.lastCheckpointTime = time.time()
Could you just always set the lastCheckpointTime?
git-p4.py class P4Sync(Command, P4UserMap): · line 3117
Quoted 11 lines
git-p4.py +4
-0for change in changes: description = p4_describe(change) self.updateOptionDict(description)@@ -3107,6 +3111,10 @@ class P4Sync(Command, P4UserMap): self.initialParent) # only needed once, to connect to the previous commit self.initialParent = "" + + if self.checkpointPeriod > -1 and time.time() - self.lastCheckpointTime > self.checkpointPeriod: + self.checkpoint() + self.lastCheckpointTime = time.time()
If you use time.time(), then this could fail to work as expected if the system time goes backwards (e.g. NTP updates). However, Python 2 doesn't have access to clock_gettime() without jumping through hoops, so perhaps we leave this as a bug until git-p4 gets ported to Python 3.
Quoted 6 lines
git-p4.py +0
-1except IOError: print self.gitError.read() sys.exit(1) --2.7.4 (Apple Git-66)
v2 cover git-p4: Add --checkpoint-period option to sync/clone
In reply to Ori RawlingsImporting a long history from Perforce into git using the git-p4 tool can be especially challenging. The git p4 clone operation is based on an all-or-nothing transactionality guarantee. Under real-world conditions like network unreliability or a busy Perforce server, git p4 clone and git p4 sync operations can easily fail, forcing a user to restart the import process from the beginning. The longer the history being imported, the more likely a fault occurs during the process. Long enough imports thus become statistically unlikely to ever succeed.
My idea was to leverage the checkpoint feature of git fast-import. I've included a patch which exposes a new option to the sync/clone commands in the git-p4 tool. The option enables explict checkpoints on a periodic basis (approximately every x seconds).
If the sync/clone command fails during processing of Perforce changes, the user can craft a new git p4 sync command that will identify changes that have already been imported and proceed with importing only changes more recent than the last successful checkpoint.
In v2 of this patch series I've added some basic test scenarios, documentation, and did some minor clean up of the implementation based on feedback on v1.
Ori Rawlings (1):
git-p4: Add --checkpoint-period option to sync/clone
Documentation/git-p4.txt | 12 ++++++- git-p4.py | 7 ++++- t/t9830-git-p4-checkpoint-period.sh | 59 ++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 0 deletions(-) create mode 100755 t/t9830-git-p4-checkpoint-period.sh
Signature · 1 line
git-series 0.8.10
PATCH v2 1/1 git-p4: Add --checkpoint-period option to sync/clone
Importing a long history from Perforce into git using the git-p4 tool can be especially challenging. The git p4 clone operation is based on an all-or-nothing transactionality guarantee. Under real-world conditions like network unreliability or a busy Perforce server, git p4 clone and git p4 sync operations can easily fail, forcing a user to restart the import process from the beginning. The longer the history being imported, the more likely a fault occurs during the process. Long enough imports thus become statistically unlikely to ever succeed.
The underlying git fast-import protocol supports an explicit checkpoint command. The idea here is to optionally allow the user to force an explicit checkpoint every <x> seconds. If the sync/clone operation fails branches are left updated at the appropriate commit available during the latest checkpoint. This allows a user to resume importing Perforce history while only having to repeat at most approximately <x> seconds worth of import activity.
--- Documentation/git-p4.txt | 12 ++++++- git-p4.py | 7 ++++- t/t9830-git-p4-checkpoint-period.sh | 59 ++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 0 deletions(-) create mode 100755 t/t9830-git-p4-checkpoint-period.sh
Documentation/git-p4.txt +12 -0
@@ -252,6 +252,18 @@ Git repository: Use a client spec to find the list of interesting files in p4. See the "CLIENT SPEC" section below. +--checkpoint-period <n>:: + Issue explicit 'checkpoint' commands to the underlying + linkgit:git-fast-import[1] approximately every 'n' seconds. If + syncing or cloning from the Perforce server is interrupted, the + process can be resumed from the most recent checkpoint with a + new 'sync' invocation. This is useful in the situations where a + large amount of changes are being imported over an unreliable + network connection. Explicit checkpoints can take up to several + minutes each, so a suitable value for the checkpoint period is + approximately 1200 seconds. By default, no explicit checkpoints + are performed. + -/ <path>:: Exclude selected depot paths when cloning or syncing.
git-p4.py +7 -0
@@ -2244,6 +2244,7 @@ class P4Sync(Command, P4UserMap): optparse.make_option("-/", dest="cloneExclude", action="append", type="string", help="exclude depot path"), + optparse.make_option("--checkpoint-period", dest="checkpointPeriod", type="int", help="Period in seconds between explict git fast-import checkpoints (by default, no explicit checkpoints are performed)"), ] self.description = """Imports from Perforce into a git repository.\n example:
@@ -2276,6 +2277,7 @@ class P4Sync(Command, P4UserMap): self.tempBranches = [] self.tempBranchLocation = "refs/git-p4-tmp" self.largeFileSystem = None + self.checkpointPeriod = None if gitConfig('git-p4.largeFileSystem'): largeFileSystemConstructor = globals()[gitConfig('git-p4.largeFileSystem')]
@@ -3031,6 +3033,7 @@ class P4Sync(Command, P4UserMap): def importChanges(self, changes): cnt = 1 + self.lastCheckpointTime = time.time() for change in changes: description = p4_describe(change) self.updateOptionDict(description)
@@ -3107,6 +3110,10 @@ class P4Sync(Command, P4UserMap): self.initialParent) # only needed once, to connect to the previous commit self.initialParent = "" + + if self.checkpointPeriod >= 0 and time.time() - self.lastCheckpointTime >= self.checkpointPeriod: + self.checkpoint() + self.lastCheckpointTime = time.time() except IOError: print self.gitError.read() sys.exit(1)
t/t9830-git-p4-checkpoint-period.sh new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
git-series 0.8.10
Re: [PATCH v2 1/1] git-p4: Add --checkpoint-period option to sync/clone
Quoted 13 lines · Ori Rawlings
Importing a long history from Perforce into git using the git-p4 tool can be especially challenging. The
git p4 cloneoperation is based on an all-or-nothing transactionality guarantee. Under real-world conditions like network unreliability or a busy Perforce server,git p4 cloneandgit p4 syncoperations can easily fail, forcing a user to restart the import process from the beginning. The longer the history being imported, the more likely a fault occurs during the process. Long enough imports thus become statistically unlikely to ever succeed.
Quoted 7 lines
The underlying git fast-import protocol supports an explicit checkpoint command. The idea here is to optionally allow the user to force an explicit checkpoint every <x> seconds. If the sync/clone operation fails branches are left updated at the appropriate commit available during the latest checkpoint. This allows a user to resume importing Perforce history while only having to repeat at most approximately <x> seconds worth of import activity.
This looks interesting! I ran into the same issue and added a parameter to the p4 commands to retry (patch not yet proposed to the mailing list):
https://github.com/autodesk-forks/git/commit/fcfc96a7814935ee6cefb9d69e44def30a90eabb
Would it make sense to print the "git-p4 resume command" in case an error happens and checkpoints are written?
Cheers,
Lars
Re: [PATCH v2 1/1] git-p4: Add --checkpoint-period option to sync/clone
Quoted 4 lines · Lars Schneider
This looks interesting! I ran into the same issue and added a parameter to the p4 commands to retry (patch not yet proposed to the mailing list):
https://github.com/autodesk-forks/git/commit/fcfc96a7814935ee6cefb9d69e44def30a90eabb
I was unaware of the retry flag to the p4 command, that seems like a useful trick too. I think both approaches might pair nicely together (p4 optimistically retrying, but still falling back to the latest git checkpoint if we exhaust our N retry attempts).
Quoted 1 line
Would it make sense to print the "git-p4 resume command" in case an error happens and checkpoints are written?
I was thinking something like this would be a good idea and would certainly aide in usability. Resuming a sync is fairly straight-forward (just re-execute the same command). Resuming a clone is a bit more problematic, today if a depot path argument is provided to the sync or clone command (and it is always required for clone), no attempt is made to examine the existing git branches and limit to only Perforce changes missing from git.
There is a lingering TODO in the script where we check the presence of the depot path argument, with a suggestion that we should always make an attempt to continue building upon existing history when it is available. I think there might be a few edge cases around this behavior that I'd need to think through. But, if I'm able to address the TODO, then printing the command to resume the import should be pretty straight-forward. I'll continue working on that next week.