Comments (7)
Can you try this...
func MongoTimestampNow() bson.MongoTimestamp {
// according to http://docs.mongodb.org/manual/reference/bson-types/
// a mongo internal timestamp is a 64 bit value where:
// the first 32 bits are a time_t value (seconds since the Unix epoch)
// the second 32 bits are an incrementing ordinal for operations within a given second.
return bson.MongoTimestamp(time.Now().Unix() << 32)
}
which could then be used as an option to tail...
ops, errs := gtm.Tail(session, >m.Options(MongoTimestampNow(), nil))
from gtm.
Yeah I tried that but it doesn't produce any output. I've verified in the mongo console that db.oplog.rs.count() is increasing, but no ops are getting reported by gtm.
from gtm.
Tried to replicate the issue but I wasn't able to... it got output that is. Here is the code I used:
package main
import "labix.org/v2/mgo"
import "labix.org/v2/mgo/bson"
import "github.com/rwynn/gtm"
import "fmt"
import "time"
func MongoTimestampNow() bson.MongoTimestamp {
return bson.MongoTimestamp(time.Now().Unix() << 32)
}
func main() {
session, err := mgo.Dial("localhost")
if err != nil {
panic(err)
}
defer session.Close()
session.SetMode(mgo.Monotonic, true)
ops, errs := gtm.Tail(session, >m.Options{MongoTimestampNow(), nil})
for {
select {
case err = <-errs:
fmt.Println(err)
case op := <-ops:
msg := fmt.Sprintf("Got op <%v> for object <%v>",
op.Operation, op.Id)
fmt.Println(msg)
}
}
}
My replica set is setup exactly as described at http://docs.mongodb.org/manual/tutorial/deploy-replica-set-for-testing/. I created a test collection in a test database, did a couple inserts and deletes after starting my go program above and I was able to see each op logged to the console.
What versions of Mongo and mgo are you using?
from gtm.
Revisited this problem and finally figured it out: if you're querying on the ts
field, you should set the OPLOG_REPLAY flag, otherwise you risk scanning the entire oplog: https://groups.google.com/d/msg/mongodb-user/E7BSv624nBg/IL9AFcsQWesJ. You can do this in mgo using LogReplay
.
from gtm.
Thanks, Rafael. I will try that option out and see how it goes. I was not able to get a query to work on the ts field directly, and as you can see from the code resorted to a $where query. If you can find a way to avoid $where using mgo for this type of query please let me know.
from gtm.
Here's what we came up with: https://github.com/Clever/mgotail. It uses a direct query on the ts field plus the LogReplay
cursor option.
from gtm.
Fix for default query has been committed. Utilizes the last timestamp in the oplog to build initial query. Added LogReplay query optimization.
from gtm.
Related Issues (20)
- Unmarshal Op.Data to a struct instead of a map HOT 6
- Delete
- Multithread direct reads HOT 14
- What to do when ctx.ErrC channel provides an error? HOT 1
- License? HOT 1
- add some tests HOT 1
- Add semver tags HOT 5
- if i want resume-from-timestamp ,How should I configure it? HOT 2
- how to use gtm to sync to a mongo primary HOT 21
- Error importing v2.0.6 with new official mongo golang package HOT 4
- whatโs the namespace ? HOT 1
- What is the difference between Op.Data and Op.Doc ๏ผ HOT 1
- Limit object reads to specific databases/collections HOT 2
- unset slice occur HOT 3
- column order problem HOT 1
- how to drop doc in es by custom id
- Possible key collision across namespaces
- Implement fanning out to multiple go routines with explicit ordering semantics
- Only default BufferDuration if zero
- Missing op.Data when alterations to same ns + id happen within same Timestamp Epoch second HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gtm.