P2P Replication it's not consistent

41 views
Skip to first unread message

Victor Fernandez

unread,
Apr 16, 2015, 5:47:15 PM4/16/15
to mobile-c...@googlegroups.com
Hi
I'm using CBLReplication object for doing a P2P connection between a network of several iPads in a Objective-c application. With bonjour I have a live mechanism that defines that the ipad with the largest IP will be the server, so the other iPads make push and pull request to the CBListener of this device.
The replication appears to work fine and quick but only whent it's active the notifier method for status KCBLReplicationActive. In other way I have to wait like a minute or a minute and a half to this method becomes active and make the peer to peer replication.
Anyone know if is correct this approach? Does any have an idea of what can I do for make this replication more quickly when is not active the notifier method? 
Regards!!  

Jens Alfke

unread,
Apr 16, 2015, 7:54:22 PM4/16/15
to mobile-c...@googlegroups.com

On Apr 16, 2015, at 2:47 PM, Victor Fernandez <vfern...@txmglobal.com> wrote:

The replication appears to work fine and quick but only whent it's active the notifier method for status KCBLReplicationActive. In other way I have to wait like a minute or a minute and a half to this method becomes active and make the peer to peer replication.

I’m having trouble understanding what you mean. Can you describe the behavior in more detail?

—Jens

Victor Fernandez

unread,
Apr 17, 2015, 1:41:25 PM4/17/15
to mobile-c...@googlegroups.com

Sure Jens, for example I have a method that trigger the P2P connection:
-(BOOL) setP2P:(NSString *) url{
    self.p2pURL = [NSURL URLWithString:url];
    self.pullP2p = [self.database createPullReplication: self.p2pURL];
    self.pushP2p = [self.database createPushReplication: self.p2pURL];
    self.pullP2p.continuous = YES;
    self.pushP2p.continuous = YES;
    NSNotificationCenter* nctr = [NSNotificationCenter defaultCenter];
    [nctr addObserver: self selector: @selector(replicationProgressP2p:)
                 name: kCBLReplicationChangeNotification object: self.pullP2p];
    [nctr addObserver: self selector: @selector(replicationProgressP2p:)
                 name: kCBLReplicationChangeNotification object: self.pushP2p];
    //Start sync
    [self.pushP2p start];
    [self.pullP2p start];
    return YES;
}

And this is the callback notifier method:
- (void) replicationProgressP2p: (NSNotificationCenter*)n {
    if (self.pullP2p.status == kCBLReplicationActive || self.pushP2p.status == kCBLReplicationActive) {
        // Sync is active -- aggregate the progress of both replications and compute a fraction:
        unsigned completed = self.pullP2p.completedChangesCount +
        self.pushP2p.completedChangesCount;
        unsigned total = self.pullP2p.changesCount +
        self.pushP2p.changesCount;
        NSLog(@"P2P SYNC progress: %u / %u", completed, total);
    }
}

My problem is that only when is active the method replicationProgressP2p the peer to peer connection works great, but when the replication becomes inactive despite I make some local database changes the method replicationProgressP2p turns active only after several time, in many scenarios takes more than a minute.
Am I explaining myself?

Thanks for your attention Jens!

Jens Alfke

unread,
Apr 20, 2015, 11:54:13 AM4/20/15
to mobile-c...@googlegroups.com

On Apr 17, 2015, at 10:41 AM, Victor Fernandez <vfern...@txmglobal.com> wrote:

My problem is that only when is active the method replicationProgressP2p the peer to peer connection works great, but when the replication becomes inactive despite I make some local database changes the method replicationProgressP2p turns active only after several time, in many scenarios takes more than a minute.

I think what you’re saying is: 

1- the initial replication catches up and the status of the push replicator goes from Active to Inactive
2- you make a local change
3- the push replicator doesn’t push the change immediately, instead it takes a minute or longer

Correct?

I’m wondering what the exact status changes are. Could you add logging to your notification handler to log the status property as well? The only explanation I can think of is that for some reason the replicator goes to Offline, meaning it doesn’t think the other device is reachable. In that case it won’t try to replicate again until the device shows up as reachable again.

—Jens

Victor Fernandez

unread,
Apr 20, 2015, 12:29:51 PM4/20/15
to mobile-c...@googlegroups.com
Hi Jens
I solved my problem setting a listener not only to events in the CBLObject also in changes on CBLDatabase.
Thanks a lot for your explanations.
Reply all
Reply to author
Forward
0 new messages