Permalink
Browse files

Fix: Pull checkpoints weren't getting restored correctly

TDPuller was saving its checkpoints to the remote JSON doc as numbers but
they were then read back and cast to string, causing the comparison to
fail. This meant the puller would start over from the beginning every time.

I also added some more logging.
  • Loading branch information...
1 parent 6728a6c commit ba085225dcd3645dc2f1dfa8af4c639b015e0573 @snej snej committed Mar 26, 2013
Showing with 9 additions and 7 deletions.
  1. +1 −0 Source/ChangeTracker/TDSocketChangeTracker.m
  2. +1 −0 Source/TDPuller.m
  3. +1 −0 Source/TDPusher.m
  4. +6 −7 Source/TDReplicator.m
@@ -92,6 +92,7 @@ - (BOOL) start {
}
// Now open the connection:
+ LogTo(SyncVerbose, @"%@: GET %@", self, url.resourceSpecifier);
CFReadStreamRef cfInputStream = CFReadStreamCreateForHTTPRequest(NULL, request);
CFRelease(request);
if (!cfInputStream)
View
@@ -192,6 +192,7 @@ - (void) changeTrackerReceivedChanges: (NSArray*)changes {
rev.remoteSequenceID = remoteSequenceID;
if (changes.count > 1)
rev.conflicted = true;
+ LogTo(SyncVerbose, @"%@: Received #%@ %@", self, remoteSequenceID, rev);
[self addToInbox: rev];
changeCount++;
View
@@ -168,6 +168,7 @@ - (void) dbChanged: (NSNotification*)n {
return;
}
+ LogTo(SyncVerbose, @"%@: Queuing #%lld %@", self, rev.sequence, rev);
[self addToInbox: rev];
}
View
@@ -164,7 +164,7 @@ - (void) setLastSequence:(NSString*)lastSequence {
- (void) postProgressChanged {
- LogTo(SyncVerbose, @"%@: postProgressChanged (%u/%u, active=%d (batch=%u, net=%u), online=%d)",
+ LogTo(Sync, @"%@: postProgressChanged (%u/%u, active=%d (batch=%u, net=%u), online=%d)",
self, (unsigned)_changesProcessed, (unsigned)_changesTotal,
_active, (unsigned)_batcher.count, _asyncTaskCount, _online);
NSNotification* n = [NSNotification notificationWithName: TDReplicatorProgressChangedNotification
@@ -411,7 +411,6 @@ - (void) asyncTasksFinished: (NSUInteger)numTasks {
- (void) addToInbox: (TD_Revision*)rev {
Assert(_running);
- LogTo(SyncVerbose, @"%@: Received #%lld %@", self, rev.sequence, rev);
[_batcher queueObject: rev];
[self updateActive];
}
@@ -596,21 +595,21 @@ - (void) fetchRemoteCheckpointDoc {
onCompletion: ^(id response, NSError* error) {
// Got the response:
if (error && error.code != kTDStatusNotFound) {
+ LogTo(Sync, @"%@: Error fetching last sequence: %@", self, error.localizedDescription);
self.error = error;
} else {
if (error.code == kTDStatusNotFound)
[self maybeCreateRemoteDB];
response = $castIf(NSDictionary, response);
self.remoteCheckpoint = response;
- NSString* remoteLastSequence = $castIf(NSString,
- response[@"lastSequence"]);
+ NSString* remoteLastSequence = response[@"lastSequence"];
if ($equal(remoteLastSequence, localLastSequence)) {
_lastSequence = localLastSequence;
LogTo(Sync, @"%@: Replicating from lastSequence=%@", self, _lastSequence);
} else {
- LogTo(Sync, @"%@: lastSequence mismatch: I had %@, remote had %@",
- self, localLastSequence, remoteLastSequence);
+ LogTo(Sync, @"%@: lastSequence mismatch: I had %@, remote had %@ (response = %@)",
+ self, localLastSequence, remoteLastSequence, response);
}
[self beginReplicating];
}
@@ -641,7 +640,7 @@ - (void) saveLastSequence {
NSMutableDictionary* body = [_remoteCheckpoint mutableCopy];
if (!body)
body = $mdict();
- [body setValue: _lastSequence forKey: @"lastSequence"];
+ [body setValue: _lastSequence.description forKey: @"lastSequence"]; // always save as a string
_savingCheckpoint = YES;
NSString* checkpointID = self.remoteCheckpointDocID;

0 comments on commit ba08522

Please sign in to comment.