github.com/team-ide/go-dialect@v1.9.20/vitess/sqltypes/event_token.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package sqltypes 18 19 import ( 20 querypb "github.com/team-ide/go-dialect/vitess/query" 21 ) 22 23 // EventTokenMinimum returns an event token that is guaranteed to 24 // happen before both provided EventToken objects. Note it doesn't 25 // parse the position, but rather only uses the timestamp. This is 26 // meant to be used for EventToken objects coming from different 27 // source shard. 28 func EventTokenMinimum(ev1, ev2 *querypb.EventToken) *querypb.EventToken { 29 if ev1 == nil || ev2 == nil { 30 // One or the other is not set, we can't do anything. 31 return nil 32 } 33 34 if ev1.Timestamp < ev2.Timestamp { 35 return &querypb.EventToken{ 36 Timestamp: ev1.Timestamp, 37 } 38 } 39 return &querypb.EventToken{ 40 Timestamp: ev2.Timestamp, 41 } 42 }