示例#1
0
        /// <summary>
        /// Handle an oplog operation.
        /// </summary>
        /// <param name="oplog">The oplog to handle.</param>
        public void HandleOperation(Oplog oplog)
        {
            if(oplog.Operation == "n")
            {
                // Operations we do not care about
                return;
            }

            switch(oplog.Operation)
            {
                case "i":
                    HandleInsert(oplog.Database, oplog.Collection, oplog.Object);
                    break;
                case "u":
                    m_outlet.Update(oplog.Database, oplog.Collection, oplog.Object2, oplog.Object);
                    break;
                case "d":
                    m_outlet.Delete(oplog.Database, oplog.Collection, oplog.Object);
                    break;
                case "c":
                    HandleCommand(oplog.Database, oplog.Collection, oplog.Object);
                    break;
                default:
                    // Unhandled operation
                    break;
            }

            m_outlet.UpdateOptime(oplog.Timestamp);
        }
示例#2
0
        /// <summary>
        /// Handle an oplog operation.
        /// </summary>
        /// <param name="oplog">The oplog to handle.</param>
        public void HandleOperation(Oplog oplog)
        {
            if (oplog.Operation == "n")
            {
                // Operations we do not care about
                return;
            }

            switch (oplog.Operation)
            {
            case "i":
                HandleInsert(oplog.Database, oplog.Collection, oplog.Object);
                break;

            case "u":
                m_outlet.Update(oplog.Database, oplog.Collection, oplog.Object2, oplog.Object);
                break;

            case "d":
                m_outlet.Delete(oplog.Database, oplog.Collection, oplog.Object);
                break;

            case "c":
                HandleCommand(oplog.Database, oplog.Collection, oplog.Object);
                break;

            default:
                // Unhandled operation
                break;
            }

            m_outlet.UpdateOptime(oplog.Timestamp);
        }
示例#3
0
        /// <summary>
        /// Get the most recent oplog.
        /// </summary>
        /// <param name="beforeTime">The timestamp to check at or before.</param>
        /// <returns>The most recent oplog at or before the given timestamp.</returns>
        public virtual async Task <Oplog> GetMostRecentOplog(BsonTimestamp beforeTime = null)
        {
            SortDefinition <Oplog> sort = Builders <Oplog> .Sort.Descending("$natural");

            FilterDefinition <Oplog> filter = new BsonDocument();

            if (beforeTime != null)
            {
                filter = Builders <Oplog> .Filter.Lte(o => o.Timestamp, beforeTime);
            }

            Oplog record = await m_oplogCollection.Find(filter).Sort(sort).FirstOrDefaultAsync();

            if (record != null)
            {
                return(record);
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// Setup the oplog tailing cursor.
        /// </summary>
        /// <param name="startOplog">The oplog to start at.</param>
        /// <returns>A task.</returns>
        public virtual async Task Tail(Oplog startOplog = null)
        {
            if (m_cursor != null)
            {
                throw new MongoRiverException("We're already talking to the oplog");
            }

            FilterDefinition <Oplog> filter = new BsonDocument();

            if (startOplog != null)
            {
                filter = Builders <Oplog> .Filter.Gt(o => o.Timestamp, startOplog.Timestamp);
            }

            var options = new FindOptions <Oplog, Oplog>
            {
                CursorType      = CursorType.TailableAwait,
                NoCursorTimeout = true
            };

            m_cursor = await m_oplogCollection.FindAsync <Oplog>(filter, options);
        }
示例#5
0
        /// <summary>
        /// Start streaming the oplog tailer forever.
        /// </summary>
        /// <param name="startOplog">The oplog to start at.</param>
        /// <returns>A never-ending task.</returns>
        public async Task RunForever(Oplog startOplog = null)
        {
            await m_tailer.Tail(startOplog);

            await m_tailer.Stream(oplog => HandleOperation(oplog));
        }
 /// <summary>
 /// Run stream for 5 seconds.
 /// </summary>
 private async Task RunStream(Stream stream, Oplog startOplog)
 {
     var task = stream.RunForever(startOplog);
     await Task.WhenAny(task, Task.Delay(5000));
     stream.Stop();
 }
 public IObservable<OpLogEvent> Create(Oplog startOplog = null)
 {
     return CreateInternal((stream, _) => stream.RunForever(startOplog));
 }
示例#8
0
        /// <summary>
        /// Setup the oplog tailing cursor.
        /// </summary>
        /// <param name="startOplog">The oplog to start at.</param>
        /// <returns>A task.</returns>
        public virtual async Task Tail(Oplog startOplog = null)
        {
            if(m_cursor != null)
            {
                throw new MongoRiverException("We're already talking to the oplog");
            }

            FilterDefinition<Oplog> filter = new BsonDocument();
            if(startOplog != null)
            {
                filter = Builders<Oplog>.Filter.Gt(o => o.Timestamp, startOplog.Timestamp);
            }

            var options = new FindOptions<Oplog, Oplog>
            {
                CursorType = CursorType.TailableAwait,
                NoCursorTimeout = true
            };

            m_cursor = await m_oplogCollection.FindAsync<Oplog>(filter, options);
        }
示例#9
0
 /// <summary>
 /// Start streaming the oplog tailer forever.
 /// </summary>
 /// <param name="startOplog">The oplog to start at.</param>
 /// <returns>A never-ending task.</returns>
 public async Task RunForever(Oplog startOplog = null)
 {
     await m_tailer.Tail(startOplog);
     await m_tailer.Stream(oplog => HandleOperation(oplog));
 }