Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/Replication.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,27 @@ public function getReplicationLog()
*/
public function putReplicationLog(array $response) {
$sessionId = \md5((\microtime(true) * 1000000));
$sourceInfo = $this->source->getDatabaseInfo($this->source->getDatabase());
if (!empty($response['end_last_seq'])) {
$last_sequence_id = $response['end_last_seq'];
}
else {
// For some reason end_last_seq was 0 on production for some cases.
// Use previous code as fallback value just subtract 5 minutes to
// prevent race condition issue.
$sourceInfo = $this->source->getDatabaseInfo($this->source->getDatabase());
$last_sequence_id = $sourceInfo['update_seq'] - 5 * 60 * 1000000;
}
$data = [
'_id' => '_local/' . $this->task->getRepId(),
'history' => [
'recorded_seq' => $sourceInfo['update_seq'],
'recorded_seq' => $last_sequence_id,
'session_id' => $sessionId,
'start_time' => $this->startTime->format('D, d M Y H:i:s e'),
'end_time' => $this->endTime->format('D, d M Y H:i:s e'),
],
'replication_id_version' => 3,
'session_id' => $sessionId,
'source_last_seq' => $sourceInfo['update_seq']
'source_last_seq' => $last_sequence_id,
];

if (isset($response['doc_write_failures'])) {
Expand Down Expand Up @@ -473,9 +482,7 @@ public function locateChangedDocumentsAndReplicate($printStatus, $getFinalReport
if (isset($changes['results'][0]['seq'])) {
$finalResponse['start_last_seq'] = $changes['results'][0]['seq'];
}
if (isset($changes['last_seq'])) {
$finalResponse['end_last_seq'] = $changes['last_seq'];
}
$finalResponse['end_last_seq'] = $since;
foreach ($response['multipartResponse'] as $docID => $res) {
// Add the response of posting each revision of the
// doc that had attachments.
Expand Down