const compactRevKey … var endpointsMapMu … var endpointsMap … func init() { … } // StartCompactor starts a compactor in the background to compact old version of keys that's not needed. // By default, we save the most recent 5 minutes data and compact versions > 5minutes ago. // It should be enough for slow watchers and to tolerate burst. // TODO: We might keep a longer history (12h) in the future once storage API can take advantage of past version of keys. func StartCompactor(ctx context.Context, client *clientv3.Client, compactInterval time.Duration) { … } // compactor periodically compacts historical versions of keys in etcd. // It will compact keys with versions older than given interval. // In other words, after compaction, it will only contain keys set during last interval. // Any API call for the older versions of keys will return error. // Interval is the time interval between each compaction. The first compaction happens after "interval". func compactor(ctx context.Context, client *clientv3.Client, interval time.Duration) { … } // compact compacts etcd store and returns current rev. // It will return the current compact time and global revision if no error occurred. // Note that CAS fail will not incur any error. func compact(ctx context.Context, client *clientv3.Client, t, rev int64) (int64, int64, error) { … }