0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

use timestamp for replication instead of Date

This commit is contained in:
Eliot Horowitz 2009-10-09 13:10:04 -04:00
parent 9c3215b828
commit ff170c0f9f
3 changed files with 32 additions and 26 deletions

View File

@ -246,6 +246,7 @@ namespace mongo {
case Bool:
return 40;
case Date:
case Timestamp:
return 45;
case RegEx:
return 50;
@ -255,8 +256,6 @@ namespace mongo {
return 60;
case CodeWScope:
return 65;
case Timestamp:
return 70;
default:
assert(0);
return -1;

View File

@ -469,7 +469,7 @@ namespace mongo {
uassert( "only source='main' allowed for now with replication", sourceName() == "main" );
BSONElement e = o.getField("syncedTo");
if ( !e.eoo() ) {
uassert( "bad sources 'syncedTo' field value", e.type() == Date );
uassert( "bad sources 'syncedTo' field value", e.type() == Date || e.type() == Timestamp );
OpTime tmp( e.date() );
syncedTo = tmp;
}
@ -507,9 +507,9 @@ namespace mongo {
if ( !only.empty() )
b.append("only", only);
if ( !syncedTo.isNull() )
b.appendDate("syncedTo", syncedTo.asDate());
b.appendTimestamp("syncedTo", syncedTo.asDate());
b.appendDate("localLogTs", lastSavedLocalTs_.asDate());
b.appendTimestamp("localLogTs", lastSavedLocalTs_.asDate());
BSONObjBuilder dbsNextPassBuilder;
int n = 0;
@ -983,7 +983,7 @@ namespace mongo {
BSONObj last = conn->findOne( _ns.c_str(), Query().sort( BSON( "$natural" << -1 ) ) );
if ( !last.isEmpty() ) {
BSONElement ts = last.findElement( "ts" );
massert( "non Date ts found", ts.type() == Date );
massert( "non Date ts found", ts.type() == Date || ts.type() == Timestamp );
syncedTo = OpTime( ts.date() );
}
}
@ -1151,7 +1151,7 @@ namespace mongo {
int n = 0;
BSONObj op = c->next();
BSONElement ts = op.findElement("ts");
if ( ts.type() != Date ) {
if ( ts.type() != Date && ts.type() != Timestamp ) {
string err = op.getStringField("$err");
if ( !err.empty() ) {
problem() << "repl: $err reading remote oplog: " + err << '\n';
@ -1243,7 +1243,7 @@ namespace mongo {
BSONObj op = c->next();
ts = op.findElement("ts");
assert( ts.type() == Date );
assert( ts.type() == Date || ts.type() == Timestamp );
OpTime last = nextOpTime;
OpTime tmp( ts.date() );
nextOpTime = tmp;
@ -1412,7 +1412,7 @@ namespace mongo {
*/
BSONObjBuilder b;
b.appendDate("ts", ts.asDate());
b.appendTimestamp("ts", ts.asDate());
b.append("op", opstr);
b.append("ns", ns);
if ( bb )

View File

@ -512,6 +512,12 @@ DB.prototype.killOp = function(){
}
DB.prototype.killOP = DB.prototype.killOp;
DB.tsToSeconds = function(x){
if ( x.t && x.i )
return x.t / 1000;
return x / 4294967296; // low 32 bits are ordinal #s within a second
}
/**
Get a replication log information summary.
<p>
@ -554,9 +560,10 @@ DB.prototype.getReplicationInfo = function() {
{
var tfirst = first.ts;
var tlast = last.ts;
if( tfirst && tlast ) {
tfirst = tfirst / 4294967296; // low 32 bits are ordinal #s within a second
tlast = tlast / 4294967296;
tfirst = DB.tsToSeconds( tfirst );
tlast = DB.tsToSeconds( tlast );
result.timeDiff = tlast - tfirst;
result.timeDiffHours = Math.round(result.timeDiff / 36)/100;
result.tFirst = (new Date(tfirst*1000)).toString();
@ -584,21 +591,21 @@ DB.prototype.printReplicationInfo = function() {
}
DB.prototype.printSlaveReplicationInfo = function() {
function g(x) {
print("source: " + x.host);
var st = new Date(x.syncedTo/4294967296*1000);
var now = new Date();
print("syncedTo: " + st.toString() );
var ago = (now-st)/1000;
var hrs = Math.round(ago/36)/100;
print(" = " + Math.round(ago) + "secs ago (" + hrs + "hrs)");
}
var L = this.getSisterDB("local");
if( L.sources.count() == 0 ) {
print("local.sources is empty; is this db a --slave?");
return;
}
L.sources.find().forEach(g);
function g(x) {
print("source: " + x.host);
var st = new Date( DB.tsToSeconds( x.syncedTo ) * 1000 );
var now = new Date();
print("syncedTo: " + st.toString() );
var ago = (now-st)/1000;
var hrs = Math.round(ago/36)/100;
print(" = " + Math.round(ago) + "secs ago (" + hrs + "hrs)");
}
var L = this.getSisterDB("local");
if( L.sources.count() == 0 ) {
print("local.sources is empty; is this db a --slave?");
return;
}
L.sources.find().forEach(g);
}
DB.prototype.serverBuildInfo = function(){