github.com/m3db/m3@v1.5.0/src/dbnode/client/types.go (about) 1 // Copyright (c) 2016 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package client 22 23 import ( 24 gocontext "context" 25 "time" 26 27 "github.com/uber/tchannel-go" 28 "github.com/uber/tchannel-go/thrift" 29 30 "github.com/m3db/m3/src/cluster/shard" 31 "github.com/m3db/m3/src/dbnode/encoding" 32 "github.com/m3db/m3/src/dbnode/generated/thrift/rpc" 33 "github.com/m3db/m3/src/dbnode/namespace" 34 "github.com/m3db/m3/src/dbnode/runtime" 35 "github.com/m3db/m3/src/dbnode/storage/block" 36 "github.com/m3db/m3/src/dbnode/storage/bootstrap/result" 37 "github.com/m3db/m3/src/dbnode/storage/index" 38 "github.com/m3db/m3/src/dbnode/topology" 39 "github.com/m3db/m3/src/x/clock" 40 "github.com/m3db/m3/src/x/context" 41 "github.com/m3db/m3/src/x/ident" 42 "github.com/m3db/m3/src/x/instrument" 43 "github.com/m3db/m3/src/x/pool" 44 xretry "github.com/m3db/m3/src/x/retry" 45 "github.com/m3db/m3/src/x/sampler" 46 "github.com/m3db/m3/src/x/serialize" 47 xsync "github.com/m3db/m3/src/x/sync" 48 xtime "github.com/m3db/m3/src/x/time" 49 ) 50 51 // Client can create sessions to write and read to a cluster. 52 type Client interface { 53 // Options returns the Client Options. 54 Options() Options 55 56 // NewSession creates a new session. 57 NewSession() (Session, error) 58 59 // NewSessionWithOptions creates a new session with the provided Options instead of the ones returned by Options. 60 NewSessionWithOptions(opts Options) (Session, error) 61 62 // DefaultSession creates a default session that gets reused. 63 DefaultSession() (Session, error) 64 65 // DefaultSessionActive returns whether the default session is active. 66 DefaultSessionActive() bool 67 } 68 69 // Session can write and read to a cluster. 70 type Session interface { 71 // WriteClusterAvailability returns whether cluster is available for writes. 72 WriteClusterAvailability() (bool, error) 73 74 // ReadClusterAvailability returns whether cluster is available for reads. 75 ReadClusterAvailability() (bool, error) 76 77 // Write value to the database for an ID. 78 Write( 79 namespace, 80 id ident.ID, 81 t xtime.UnixNano, 82 value float64, 83 unit xtime.Unit, 84 annotation []byte, 85 ) error 86 87 // WriteTagged value to the database for an ID and given tags. 88 WriteTagged( 89 namespace, 90 id ident.ID, 91 tags ident.TagIterator, 92 t xtime.UnixNano, 93 value float64, 94 unit xtime.Unit, 95 annotation []byte, 96 ) error 97 98 // Fetch values from the database for an ID. 99 Fetch( 100 namespace, 101 id ident.ID, 102 startInclusive, 103 endExclusive xtime.UnixNano, 104 ) (encoding.SeriesIterator, error) 105 106 // FetchIDs values from the database for a set of IDs. 107 FetchIDs( 108 namespace ident.ID, 109 ids ident.Iterator, 110 startInclusive, 111 endExclusive xtime.UnixNano, 112 ) (encoding.SeriesIterators, error) 113 114 // FetchTagged resolves the provided query to known IDs, and fetches the data for them. 115 FetchTagged( 116 ctx gocontext.Context, 117 namespace ident.ID, 118 q index.Query, 119 opts index.QueryOptions, 120 ) (encoding.SeriesIterators, FetchResponseMetadata, error) 121 122 // FetchTaggedIDs resolves the provided query to known IDs. 123 FetchTaggedIDs( 124 ctx gocontext.Context, 125 namespace ident.ID, 126 q index.Query, 127 opts index.QueryOptions, 128 ) (TaggedIDsIterator, FetchResponseMetadata, error) 129 130 // Aggregate aggregates values from the database for the given set of constraints. 131 Aggregate( 132 ctx gocontext.Context, 133 namespace ident.ID, 134 q index.Query, 135 opts index.AggregationOptions, 136 ) (AggregatedTagsIterator, FetchResponseMetadata, error) 137 138 // ShardID returns the given shard for an ID for callers 139 // to easily discern what shard is failing when operations 140 // for given IDs begin failing. 141 ShardID(id ident.ID) (uint32, error) 142 143 // IteratorPools exposes the internal iterator pools used by the session to clients. 144 IteratorPools() (encoding.IteratorPools, error) 145 146 // Close the session 147 Close() error 148 } 149 150 // FetchResponseMetadata is metadata about a fetch response. 151 type FetchResponseMetadata struct { 152 // Exhaustive indicates whether the underlying data set presents a full 153 // collection of retrieved data. 154 Exhaustive bool 155 // Responses is the count of responses. 156 Responses int 157 // EstimateTotalBytes is an approximation of the total byte size of the response. 158 EstimateTotalBytes int 159 // WaitedIndex counts how many times index querying had to wait for permits. 160 WaitedIndex int 161 // WaitedSeriesRead counts how many times series being read had to wait for permits. 162 WaitedSeriesRead int 163 } 164 165 // AggregatedTagsIterator iterates over a collection of tag names with optionally 166 // associated values. 167 type AggregatedTagsIterator interface { 168 // Next returns whether there are more items in the collection. 169 Next() bool 170 171 // Remaining returns the number of elements remaining to be iterated over. 172 Remaining() int 173 174 // Current returns the current tagName, and associated tagValues iterator. 175 // These remain valid until Next() is called again. 176 Current() (tagName ident.ID, tagValues ident.Iterator) 177 178 // Err returns any error encountered. 179 Err() error 180 181 // Finalize releases any held resources. 182 Finalize() 183 } 184 185 // TaggedIDsIterator iterates over a collection of IDs with associated tags and namespace. 186 type TaggedIDsIterator interface { 187 // Next returns whether there are more items in the collection. 188 Next() bool 189 190 // Remaining returns the number of elements remaining to be iterated over. 191 Remaining() int 192 193 // Current returns the ID, Tags and Namespace for a single timeseries. 194 // These remain valid until Next() is called again. 195 Current() (namespaceID ident.ID, seriesID ident.ID, tags ident.TagIterator) 196 197 // Err returns any error encountered. 198 Err() error 199 200 // Finalize releases any held resources. 201 Finalize() 202 } 203 204 // AdminClient can create administration sessions. 205 type AdminClient interface { 206 Client 207 208 // NewAdminSession creates a new admin session. 209 NewAdminSession() (AdminSession, error) 210 211 // DefaultAdminSession creates a default admin session that gets reused. 212 DefaultAdminSession() (AdminSession, error) 213 } 214 215 // PeerBlockMetadataIter iterates over a collection of 216 // blocks metadata from peers. 217 type PeerBlockMetadataIter interface { 218 // Next returns whether there are more items in the collection. 219 Next() bool 220 221 // Current returns the host and block metadata, which remain 222 // valid until Next() is called again. 223 Current() (topology.Host, block.Metadata) 224 225 // Err returns any error encountered 226 Err() error 227 } 228 229 // PeerBlocksIter iterates over a collection of blocks from peers. 230 type PeerBlocksIter interface { 231 // Next returns whether there are more items in the collection. 232 Next() bool 233 234 // Current returns the metadata, and block data for a single block replica. 235 // These remain valid until Next() is called again. 236 Current() (topology.Host, ident.ID, ident.Tags, block.DatabaseBlock) 237 238 // Err returns any error encountered. 239 Err() error 240 } 241 242 // AdminSession can perform administrative and node-to-node operations. 243 type AdminSession interface { 244 Session 245 246 // Origin returns the host that initiated the session. 247 Origin() topology.Host 248 249 // Replicas returns the replication factor. 250 Replicas() int 251 252 // TopologyMap returns the current topology map. Note that the session 253 // has a separate topology watch than the database itself, so the two 254 // values can be out of sync and this method should not be relied upon 255 // if the current view of the topology as seen by the database is required. 256 TopologyMap() (topology.Map, error) 257 258 // Truncate will truncate the namespace for a given shard. 259 Truncate(namespace ident.ID) (int64, error) 260 261 // FetchBootstrapBlocksFromPeers will fetch the most fulfilled block 262 // for each series using the runtime configurable bootstrap level consistency. 263 FetchBootstrapBlocksFromPeers( 264 namespace namespace.Metadata, 265 shard uint32, 266 start, end xtime.UnixNano, 267 opts result.Options, 268 ) (result.ShardResult, error) 269 270 // FetchBootstrapBlocksMetadataFromPeers will fetch the blocks metadata from 271 // available peers using the runtime configurable bootstrap level consistency. 272 FetchBootstrapBlocksMetadataFromPeers( 273 namespace ident.ID, 274 shard uint32, 275 start, end xtime.UnixNano, 276 result result.Options, 277 ) (PeerBlockMetadataIter, error) 278 279 // FetchBlocksMetadataFromPeers will fetch the blocks metadata from 280 // available peers. 281 FetchBlocksMetadataFromPeers( 282 namespace ident.ID, 283 shard uint32, 284 start, end xtime.UnixNano, 285 consistencyLevel topology.ReadConsistencyLevel, 286 result result.Options, 287 ) (PeerBlockMetadataIter, error) 288 289 // FetchBlocksFromPeers will fetch the required blocks from the 290 // peers specified. 291 FetchBlocksFromPeers( 292 namespace namespace.Metadata, 293 shard uint32, 294 consistencyLevel topology.ReadConsistencyLevel, 295 metadatas []block.ReplicaMetadata, 296 opts result.Options, 297 ) (PeerBlocksIter, error) 298 299 // BorrowConnections will borrow connection for hosts belonging to a shard. 300 BorrowConnections( 301 shardID uint32, 302 fn WithBorrowConnectionFn, 303 opts BorrowConnectionOptions, 304 ) (BorrowConnectionsResult, error) 305 306 // DedicatedConnection will open and health check a new connection to one of the 307 // hosts belonging to a shard. The connection should be used for long running requests. 308 // For normal requests consider using BorrowConnections. 309 DedicatedConnection( 310 shardID uint32, 311 opts DedicatedConnectionOptions, 312 ) (rpc.TChanNode, Channel, error) 313 } 314 315 // BorrowConnectionOptions are options to use when borrowing a connection 316 type BorrowConnectionOptions struct { 317 // ContinueOnBorrowError allows skipping hosts that cannot borrow 318 // a connection for. 319 ContinueOnBorrowError bool 320 // ExcludeOrigin will exclude attempting to borrow a connection for 321 // the origin host (i.e. the local host). 322 ExcludeOrigin bool 323 } 324 325 // BorrowConnectionsResult is a result used when borrowing connections. 326 type BorrowConnectionsResult struct { 327 Borrowed int 328 } 329 330 // WithBorrowConnectionFn is used to do work with a borrowed connection. 331 type WithBorrowConnectionFn func( 332 shard shard.Shard, 333 host topology.Host, 334 client rpc.TChanNode, 335 channel Channel, 336 ) (WithBorrowConnectionResult, error) 337 338 // WithBorrowConnectionResult is returned from a borrow connection function. 339 type WithBorrowConnectionResult struct { 340 // Break will break the iteration. 341 Break bool 342 } 343 344 // DedicatedConnectionOptions are options used for getting a dedicated connection. 345 type DedicatedConnectionOptions struct { 346 ShardStateFilter shard.State 347 BootstrappedNodesOnly bool 348 } 349 350 // Options is a set of client options. 351 type Options interface { 352 // Validate validates the options. 353 Validate() error 354 355 // SetEncodingM3TSZ sets M3TSZ encoding. 356 SetEncodingM3TSZ() Options 357 358 // SetEncodingProto sets proto encoding. 359 SetEncodingProto(encodingOpts encoding.Options) Options 360 361 // IsSetEncodingProto returns whether proto encoding is set. 362 IsSetEncodingProto() bool 363 364 // SetRuntimeOptionsManager sets the runtime options manager, it is optional 365 SetRuntimeOptionsManager(value runtime.OptionsManager) Options 366 367 // RuntimeOptionsManager returns the runtime options manager, it is optional. 368 RuntimeOptionsManager() runtime.OptionsManager 369 370 // SetClockOptions sets the clock options. 371 SetClockOptions(value clock.Options) Options 372 373 // ClockOptions returns the clock options. 374 ClockOptions() clock.Options 375 376 // SetInstrumentOptions sets the instrumentation options. 377 SetInstrumentOptions(value instrument.Options) Options 378 379 // InstrumentOptions returns the instrumentation options. 380 InstrumentOptions() instrument.Options 381 382 // SetLogErrorSampleRate sets the log error sample rate between [0,1.0]. 383 SetLogErrorSampleRate(value sampler.Rate) Options 384 385 // LogErrorSampleRate returns the log error sample rate between [0,1.0]. 386 LogErrorSampleRate() sampler.Rate 387 388 // SetTopologyInitializer sets the TopologyInitializer. 389 SetTopologyInitializer(value topology.Initializer) Options 390 391 // TopologyInitializer returns the TopologyInitializer. 392 TopologyInitializer() topology.Initializer 393 394 // SetReadConsistencyLevel sets the read consistency level. 395 SetReadConsistencyLevel(value topology.ReadConsistencyLevel) Options 396 397 // ReadConsistencyLevel returns the read consistency level. 398 ReadConsistencyLevel() topology.ReadConsistencyLevel 399 400 // SetWriteConsistencyLevel sets the write consistency level. 401 SetWriteConsistencyLevel(value topology.ConsistencyLevel) Options 402 403 // WriteConsistencyLevel returns the write consistency level. 404 WriteConsistencyLevel() topology.ConsistencyLevel 405 406 // SetChannelOptions sets the channelOptions. 407 SetChannelOptions(value *tchannel.ChannelOptions) Options 408 409 // ChannelOptions returns the channelOptions. 410 ChannelOptions() *tchannel.ChannelOptions 411 412 // SetMaxConnectionCount sets the maxConnectionCount. 413 SetMaxConnectionCount(value int) Options 414 415 // MaxConnectionCount returns the maxConnectionCount. 416 MaxConnectionCount() int 417 418 // SetMinConnectionCount sets the minConnectionCount. 419 SetMinConnectionCount(value int) Options 420 421 // MinConnectionCount returns the minConnectionCount. 422 MinConnectionCount() int 423 424 // SetHostConnectTimeout sets the hostConnectTimeout. 425 SetHostConnectTimeout(value time.Duration) Options 426 427 // HostConnectTimeout returns the hostConnectTimeout. 428 HostConnectTimeout() time.Duration 429 430 // SetClusterConnectTimeout sets the clusterConnectTimeout. 431 SetClusterConnectTimeout(value time.Duration) Options 432 433 // ClusterConnectTimeout returns the clusterConnectTimeout. 434 ClusterConnectTimeout() time.Duration 435 436 // SetClusterConnectConsistencyLevel sets the clusterConnectConsistencyLevel. 437 SetClusterConnectConsistencyLevel(value topology.ConnectConsistencyLevel) Options 438 439 // ClusterConnectConsistencyLevel returns the clusterConnectConsistencyLevel. 440 ClusterConnectConsistencyLevel() topology.ConnectConsistencyLevel 441 442 // SetWriteRequestTimeout sets the writeRequestTimeout. 443 SetWriteRequestTimeout(value time.Duration) Options 444 445 // WriteRequestTimeout returns the writeRequestTimeout. 446 WriteRequestTimeout() time.Duration 447 448 // SetFetchRequestTimeout sets the fetchRequestTimeout. 449 SetFetchRequestTimeout(value time.Duration) Options 450 451 // FetchRequestTimeout returns the fetchRequestTimeout. 452 FetchRequestTimeout() time.Duration 453 454 // SetTruncateRequestTimeout sets the truncateRequestTimeout. 455 SetTruncateRequestTimeout(value time.Duration) Options 456 457 // TruncateRequestTimeout returns the truncateRequestTimeout. 458 TruncateRequestTimeout() time.Duration 459 460 // SetBackgroundConnectInterval sets the backgroundConnectInterval. 461 SetBackgroundConnectInterval(value time.Duration) Options 462 463 // BackgroundConnectInterval returns the backgroundConnectInterval. 464 BackgroundConnectInterval() time.Duration 465 466 // SetBackgroundConnectStutter sets the backgroundConnectStutter. 467 SetBackgroundConnectStutter(value time.Duration) Options 468 469 // BackgroundConnectStutter returns the backgroundConnectStutter. 470 BackgroundConnectStutter() time.Duration 471 472 // SetBackgroundHealthCheckInterval sets the background health check interval 473 SetBackgroundHealthCheckInterval(value time.Duration) Options 474 475 // BackgroundHealthCheckInterval returns the background health check interval 476 BackgroundHealthCheckInterval() time.Duration 477 478 // SetBackgroundHealthCheckStutter sets the background health check stutter 479 SetBackgroundHealthCheckStutter(value time.Duration) Options 480 481 // BackgroundHealthCheckStutter returns the background health check stutter 482 BackgroundHealthCheckStutter() time.Duration 483 484 // SetBackgroundHealthCheckFailLimit sets the background health failure 485 // limit before connection is deemed unhealth 486 SetBackgroundHealthCheckFailLimit(value int) Options 487 488 // BackgroundHealthCheckFailLimit returns the background health failure 489 // limit before connection is deemed unhealth 490 BackgroundHealthCheckFailLimit() int 491 492 // SetBackgroundHealthCheckFailThrottleFactor sets the throttle factor to 493 // apply when calculating how long to wait between a failed health check and 494 // a retry attempt. It is applied by multiplying against the host connect 495 // timeout to produce a throttle sleep value. 496 SetBackgroundHealthCheckFailThrottleFactor(value float64) Options 497 498 // BackgroundHealthCheckFailThrottleFactor returns the throttle factor to 499 // apply when calculating how long to wait between a failed health check and 500 // a retry attempt. It is applied by multiplying against the host connect 501 // timeout to produce a throttle sleep value. 502 BackgroundHealthCheckFailThrottleFactor() float64 503 504 // SetWriteRetrier sets the write retrier when performing a write for 505 // a write operation. Only retryable errors are retried. 506 SetWriteRetrier(value xretry.Retrier) Options 507 508 // WriteRetrier returns the write retrier when perform a write for 509 // a write operation. Only retryable errors are retried. 510 WriteRetrier() xretry.Retrier 511 512 // SetFetchRetrier sets the fetch retrier when performing a write for 513 // a fetch operation. Only retryable errors are retried. 514 SetFetchRetrier(value xretry.Retrier) Options 515 516 // FetchRetrier returns the fetch retrier when performing a fetch for 517 // a fetch operation. Only retryable errors are retried. 518 FetchRetrier() xretry.Retrier 519 520 // SetWriteShardsInitializing sets whether to write to shards that are 521 // initializing or not. 522 SetWriteShardsInitializing(value bool) Options 523 524 // WriteShardsInitializing returns whether to write to shards that are 525 // initializing or not. 526 WriteShardsInitializing() bool 527 528 // SetShardsLeavingCountTowardsConsistency sets whether to count shards 529 // that are leaving or not towards consistency level calculations. 530 SetShardsLeavingCountTowardsConsistency(value bool) Options 531 532 // ShardsLeavingCountTowardsConsistency returns whether to count shards 533 // that are leaving or not towards consistency level calculations. 534 ShardsLeavingCountTowardsConsistency() bool 535 536 // SetTagEncoderOptions sets the TagEncoderOptions. 537 SetTagEncoderOptions(value serialize.TagEncoderOptions) Options 538 539 // TagEncoderOptions returns the TagEncoderOptions. 540 TagEncoderOptions() serialize.TagEncoderOptions 541 542 // SetTagEncoderPoolSize sets the TagEncoderPoolSize. 543 SetTagEncoderPoolSize(value pool.Size) Options 544 545 // TagEncoderPoolSize returns the TagEncoderPoolSize. 546 TagEncoderPoolSize() pool.Size 547 548 // SetTagDecoderOptions sets the TagDecoderOptions. 549 SetTagDecoderOptions(value serialize.TagDecoderOptions) Options 550 551 // TagDecoderOptions returns the TagDecoderOptions. 552 TagDecoderOptions() serialize.TagDecoderOptions 553 554 // SetTagDecoderPoolSize sets the TagDecoderPoolSize. 555 SetTagDecoderPoolSize(value pool.Size) Options 556 557 // TagDecoderPoolSize returns the TagDecoderPoolSize. 558 TagDecoderPoolSize() pool.Size 559 560 // SetWriteBatchSize sets the writeBatchSize 561 // NB(r): for a write only application load this should match the host 562 // queue ops flush size so that each time a host queue is flushed it can 563 // fit the entire flushed write ops into a single batch. 564 SetWriteBatchSize(value int) Options 565 566 // WriteBatchSize returns the writeBatchSize. 567 WriteBatchSize() int 568 569 // SetFetchBatchSize sets the fetchBatchSize 570 // NB(r): for a fetch only application load this should match the host 571 // queue ops flush size so that each time a host queue is flushed it can 572 // fit the entire flushed fetch ops into a single batch. 573 SetFetchBatchSize(value int) Options 574 575 // FetchBatchSize returns the fetchBatchSize. 576 FetchBatchSize() int 577 578 // SetWriteOpPoolSize sets the writeOperationPoolSize. 579 SetWriteOpPoolSize(value pool.Size) Options 580 581 // WriteOpPoolSize returns the writeOperationPoolSize. 582 WriteOpPoolSize() pool.Size 583 584 // SetWriteTaggedOpPoolSize sets the writeTaggedOperationPoolSize. 585 SetWriteTaggedOpPoolSize(value pool.Size) Options 586 587 // WriteTaggedOpPoolSize returns the writeTaggedOperationPoolSize. 588 WriteTaggedOpPoolSize() pool.Size 589 590 // SetFetchBatchOpPoolSize sets the fetchBatchOpPoolSize. 591 SetFetchBatchOpPoolSize(value pool.Size) Options 592 593 // FetchBatchOpPoolSize returns the fetchBatchOpPoolSize. 594 FetchBatchOpPoolSize() pool.Size 595 596 // SetCheckedBytesWrapperPoolSize sets the checkedBytesWrapperPoolSize. 597 SetCheckedBytesWrapperPoolSize(value pool.Size) Options 598 599 // CheckedBytesWrapperPoolSize returns the checkedBytesWrapperPoolSize. 600 CheckedBytesWrapperPoolSize() pool.Size 601 602 // SetHostQueueOpsFlushSize sets the hostQueueOpsFlushSize. 603 SetHostQueueOpsFlushSize(value int) Options 604 605 // HostQueueOpsFlushSize returns the hostQueueOpsFlushSize. 606 HostQueueOpsFlushSize() int 607 608 // SetHostQueueOpsFlushInterval sets the hostQueueOpsFlushInterval. 609 SetHostQueueOpsFlushInterval(value time.Duration) Options 610 611 // HostQueueOpsFlushInterval returns the hostQueueOpsFlushInterval. 612 HostQueueOpsFlushInterval() time.Duration 613 614 // SetContextPool sets the contextPool. 615 SetContextPool(value context.Pool) Options 616 617 // ContextPool returns the contextPool. 618 ContextPool() context.Pool 619 620 // SetCheckedBytesPool sets the checked bytes pool. 621 SetCheckedBytesPool(value pool.CheckedBytesPool) Options 622 623 // CheckedBytesPool returns the checked bytes pool. 624 CheckedBytesPool() pool.CheckedBytesPool 625 626 // SetIdentifierPool sets the identifier pool. 627 SetIdentifierPool(value ident.Pool) Options 628 629 // IdentifierPool returns the identifier pool. 630 IdentifierPool() ident.Pool 631 632 // SetHostQueueOpsArrayPoolSize sets the hostQueueOpsArrayPoolSize. 633 SetHostQueueOpsArrayPoolSize(value pool.Size) Options 634 635 // HostQueueOpsArrayPoolSize returns the hostQueueOpsArrayPoolSize. 636 HostQueueOpsArrayPoolSize() pool.Size 637 638 // SetHostQueueNewPooledWorkerFn sets the host queue new pooled worker function. 639 SetHostQueueNewPooledWorkerFn(value xsync.NewPooledWorkerFn) Options 640 641 // HostQueueNewPooledWorkerFn sets the host queue new pooled worker function. 642 HostQueueNewPooledWorkerFn() xsync.NewPooledWorkerFn 643 644 // SetHostQueueEmitsHealthStatus sets the hostQueueEmitHealthStatus. 645 SetHostQueueEmitsHealthStatus(value bool) Options 646 647 // HostQueueEmitsHealthStatus returns the hostQueueEmitHealthStatus. 648 HostQueueEmitsHealthStatus() bool 649 650 // SetSeriesIteratorPoolSize sets the seriesIteratorPoolSize. 651 SetSeriesIteratorPoolSize(value pool.Size) Options 652 653 // SeriesIteratorPoolSize returns the seriesIteratorPoolSize. 654 SeriesIteratorPoolSize() pool.Size 655 656 // SetReaderIteratorAllocate sets the readerIteratorAllocate. 657 SetReaderIteratorAllocate(value encoding.ReaderIteratorAllocate) Options 658 659 // ReaderIteratorAllocate returns the readerIteratorAllocate. 660 ReaderIteratorAllocate() encoding.ReaderIteratorAllocate 661 662 // SetSchemaRegistry sets the schema registry. 663 SetSchemaRegistry(registry namespace.SchemaRegistry) AdminOptions 664 665 // SchemaRegistry returns the schema registry. 666 SchemaRegistry() namespace.SchemaRegistry 667 668 // SetAsyncTopologyInitializers sets the AsyncTopologyInitializers 669 SetAsyncTopologyInitializers(value []topology.Initializer) Options 670 671 // AsyncTopologyInitializers returns the AsyncTopologyInitializers 672 AsyncTopologyInitializers() []topology.Initializer 673 674 // SetAsyncWriteWorkerPool sets the worker pool for async writes. 675 SetAsyncWriteWorkerPool(value xsync.PooledWorkerPool) Options 676 677 // AsyncWriteWorkerPool returns the worker pool for async writes. 678 AsyncWriteWorkerPool() xsync.PooledWorkerPool 679 680 // SetAsyncWriteMaxConcurrency sets the async writes maximum concurrency. 681 SetAsyncWriteMaxConcurrency(value int) Options 682 683 // AsyncWriteMaxConcurrency returns the async writes maximum concurrency. 684 AsyncWriteMaxConcurrency() int 685 686 // SetUseV2BatchAPIs sets whether the V2 batch APIs should be used. 687 SetUseV2BatchAPIs(value bool) Options 688 689 // UseV2BatchAPIs returns whether the V2 batch APIs should be used. 690 UseV2BatchAPIs() bool 691 692 // SetIterationOptions sets experimental iteration options. 693 SetIterationOptions(index.IterationOptions) Options 694 695 // IterationOptions returns experimental iteration options. 696 IterationOptions() index.IterationOptions 697 698 // SetWriteTimestampOffset sets the write timestamp offset. 699 SetWriteTimestampOffset(value time.Duration) AdminOptions 700 701 // WriteTimestampOffset returns the write timestamp offset. 702 WriteTimestampOffset() time.Duration 703 704 // SetNewConnectionFn sets a new connection generator function. 705 SetNewConnectionFn(value NewConnectionFn) AdminOptions 706 707 // NewConnectionFn returns the new connection generator function. 708 NewConnectionFn() NewConnectionFn 709 710 // SetNamespaceInitializer sets the NamespaceInitializer used to generate a namespace.Registry object 711 // that can be used to watch namespaces. 712 SetNamespaceInitializer(value namespace.Initializer) Options 713 714 // NamespaceInitializer returns the NamespaceInitializer. 715 NamespaceInitializer() namespace.Initializer 716 717 // SetThriftContextFn sets the retrier for streaming blocks. 718 SetThriftContextFn(value ThriftContextFn) Options 719 720 // ThriftContextFn returns the retrier for streaming blocks. 721 ThriftContextFn() ThriftContextFn 722 } 723 724 // ThriftContextFn turns a context into a thrift context for a thrift call. 725 type ThriftContextFn func(gocontext.Context) thrift.Context 726 727 // AdminOptions is a set of administration client options. 728 type AdminOptions interface { 729 Options 730 731 // SetOrigin sets the current host originating requests from. 732 SetOrigin(value topology.Host) AdminOptions 733 734 // Origin gets the current host originating requests from. 735 Origin() topology.Host 736 737 // SetBootstrapConsistencyLevel sets the bootstrap consistency level. 738 SetBootstrapConsistencyLevel(value topology.ReadConsistencyLevel) AdminOptions 739 740 // BootstrapConsistencyLevel returns the bootstrap consistency level. 741 BootstrapConsistencyLevel() topology.ReadConsistencyLevel 742 743 // SetFetchSeriesBlocksMaxBlockRetries sets the max retries for fetching series blocks. 744 SetFetchSeriesBlocksMaxBlockRetries(value int) AdminOptions 745 746 // FetchSeriesBlocksMaxBlockRetries gets the max retries for fetching series blocks. 747 FetchSeriesBlocksMaxBlockRetries() int 748 749 // SetFetchSeriesBlocksBatchSize sets the batch size for fetching series blocks in batch. 750 SetFetchSeriesBlocksBatchSize(value int) AdminOptions 751 752 // FetchSeriesBlocksBatchSize gets the batch size for fetching series blocks in batch. 753 FetchSeriesBlocksBatchSize() int 754 755 // SetFetchSeriesBlocksMetadataBatchTimeout sets the timeout for fetching series blocks metadata in batch. 756 SetFetchSeriesBlocksMetadataBatchTimeout(value time.Duration) AdminOptions 757 758 // FetchSeriesBlocksMetadataBatchTimeout gets the timeout for fetching series blocks metadata in batch. 759 FetchSeriesBlocksMetadataBatchTimeout() time.Duration 760 761 // SetFetchSeriesBlocksBatchTimeout sets the timeout for fetching series blocks in batch. 762 SetFetchSeriesBlocksBatchTimeout(value time.Duration) AdminOptions 763 764 // FetchSeriesBlocksBatchTimeout gets the timeout for fetching series blocks in batch. 765 FetchSeriesBlocksBatchTimeout() time.Duration 766 767 // SetFetchSeriesBlocksBatchConcurrency sets the concurrency for fetching series blocks in batch. 768 SetFetchSeriesBlocksBatchConcurrency(value int) AdminOptions 769 770 // FetchSeriesBlocksBatchConcurrency gets the concurrency for fetching series blocks in batch. 771 FetchSeriesBlocksBatchConcurrency() int 772 773 // SetStreamBlocksRetrier sets the retrier for streaming blocks. 774 SetStreamBlocksRetrier(value xretry.Retrier) AdminOptions 775 776 // StreamBlocksRetrier returns the retrier for streaming blocks. 777 StreamBlocksRetrier() xretry.Retrier 778 } 779 780 // The rest of these types are internal types that mocks are generated for 781 // in file mode and hence need to stay in this file and refer to the other 782 // types such as AdminSession. When mocks are generated in file mode the 783 // other types they reference need to be in the same file. 784 785 type clientSession interface { 786 AdminSession 787 788 // Open the client session. 789 Open() error 790 } 791 792 type hostQueue interface { 793 // Open the host queue. 794 Open() 795 796 // Len returns the length of the queue. 797 Len() int 798 799 // Enqueue an operation. 800 Enqueue(op op) error 801 802 // Host gets the host. 803 Host() topology.Host 804 805 // ConnectionCount gets the current open connection count. 806 ConnectionCount() int 807 808 // ConnectionPool gets the connection pool. 809 ConnectionPool() connectionPool 810 811 // BorrowConnection will borrow a connection and execute a user function. 812 BorrowConnection(fn WithConnectionFn) error 813 814 // Close the host queue, will flush any operations still pending. 815 Close() 816 } 817 818 // WithConnectionFn is a callback for a connection to a host. 819 type WithConnectionFn func(client rpc.TChanNode, ch Channel) 820 821 // Channel is an interface for tchannel.Channel struct. 822 type Channel interface { 823 GetSubChannel(serviceName string, opts ...tchannel.SubChannelOption) *tchannel.SubChannel 824 Close() 825 } 826 827 type connectionPool interface { 828 // Open starts the connection pool connecting and health checking. 829 Open() 830 831 // ConnectionCount gets the current open connection count. 832 ConnectionCount() int 833 834 // NextClient gets the next client for use by the connection pool. 835 NextClient() (rpc.TChanNode, Channel, error) 836 837 // Close the connection pool. 838 Close() 839 } 840 841 type peerSource interface { 842 // BorrowConnection will borrow a connection and execute a user function. 843 BorrowConnection(hostID string, fn WithConnectionFn) error 844 } 845 846 type peer interface { 847 // Host gets the host. 848 Host() topology.Host 849 850 // BorrowConnection will borrow a connection and execute a user function. 851 BorrowConnection(fn WithConnectionFn) error 852 } 853 854 type status int 855 856 const ( 857 statusNotOpen status = iota 858 statusOpen 859 statusClosed 860 ) 861 862 type healthStatus int 863 864 const ( 865 healthStatusCheckFailed healthStatus = iota 866 healthStatusOK 867 ) 868 869 type op interface { 870 // Size returns the effective size of inner operations. 871 Size() int 872 873 // CompletionFn gets the completion function for the operation. 874 CompletionFn() completionFn 875 } 876 877 type enqueueDelayedFn func(peersMetadata []receivedBlockMetadata) 878 type enqueueDelayedDoneFn func() 879 880 type enqueueChannel interface { 881 enqueue(peersMetadata []receivedBlockMetadata) error 882 enqueueDelayed(numToEnqueue int) (enqueueDelayedFn, enqueueDelayedDoneFn, error) 883 // read is always safe to call since you can safely range 884 // over a closed channel, and/or do a checked read in case 885 // it is closed (unlike when publishing to a channel). 886 read() <-chan []receivedBlockMetadata 887 trackPending(amount int) 888 trackProcessed(amount int) 889 unprocessedLen() int 890 closeOnAllProcessed() 891 }