/// <summary>
        /// Parses <see cref="GtidEvent"/> from the buffer.
        /// </summary>
        public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
        {
            var flags         = reader.ReadByte();
            var sourceId      = new Uuid(reader.ReadByteArraySlow(16));
            var transactionId = reader.ReadInt64LittleEndian();
            var gtid          = new Gtid(sourceId, transactionId);

            return(new GtidEvent(header, gtid, flags));
        }
Exemple #2
0
        /// <summary>
        /// Adds a gtid value to the UuidSet.
        /// </summary>
        public bool AddGtid(Gtid gtid)
        {
            if (SourceId != gtid.SourceId)
            {
                throw new ArgumentException("SourceId of the passed gtid doesn't belong to the UuidSet");
            }

            int  index = FindIntervalIndex(gtid.TransactionId);
            bool added = false;

            if (index < Intervals.Count)
            {
                var interval = Intervals[index];
                if (interval.Start == gtid.TransactionId + 1)
                {
                    interval.Start = gtid.TransactionId;
                    added          = true;
                }
                else if (interval.End + 1 == gtid.TransactionId)
                {
                    interval.End = gtid.TransactionId;
                    added        = true;
                }
                else if (interval.Start <= gtid.TransactionId && gtid.TransactionId <= interval.End)
                {
                    return(false);
                }
            }
            if (!added)
            {
                Intervals.Insert(index, new Interval(gtid.TransactionId, gtid.TransactionId));
            }
            if (Intervals.Count > 1)
            {
                CollapseIntervals();
            }
            return(true);
        }