retrying-call.d.ts 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /// <reference types="node" />
  2. import { CallCredentials } from './call-credentials';
  3. import { Status } from './constants';
  4. import { Deadline } from './deadline';
  5. import { Metadata } from './metadata';
  6. import { CallConfig } from './resolver';
  7. import { Call, DeadlineInfoProvider, InterceptingListener, MessageContext } from './call-interface';
  8. import { InternalChannel } from './internal-channel';
  9. export declare class RetryThrottler {
  10. private readonly maxTokens;
  11. private readonly tokenRatio;
  12. private tokens;
  13. constructor(maxTokens: number, tokenRatio: number, previousRetryThrottler?: RetryThrottler);
  14. addCallSucceeded(): void;
  15. addCallFailed(): void;
  16. canRetryCall(): boolean;
  17. }
  18. export declare class MessageBufferTracker {
  19. private totalLimit;
  20. private limitPerCall;
  21. private totalAllocated;
  22. private allocatedPerCall;
  23. constructor(totalLimit: number, limitPerCall: number);
  24. allocate(size: number, callId: number): boolean;
  25. free(size: number, callId: number): void;
  26. freeAll(callId: number): void;
  27. }
  28. export declare class RetryingCall implements Call, DeadlineInfoProvider {
  29. private readonly channel;
  30. private readonly callConfig;
  31. private readonly methodName;
  32. private readonly host;
  33. private readonly credentials;
  34. private readonly deadline;
  35. private readonly callNumber;
  36. private readonly bufferTracker;
  37. private readonly retryThrottler?;
  38. private state;
  39. private listener;
  40. private initialMetadata;
  41. private underlyingCalls;
  42. private writeBuffer;
  43. /**
  44. * The offset of message indices in the writeBuffer. For example, if
  45. * writeBufferOffset is 10, message 10 is in writeBuffer[0] and message 15
  46. * is in writeBuffer[5].
  47. */
  48. private writeBufferOffset;
  49. /**
  50. * Tracks whether a read has been started, so that we know whether to start
  51. * reads on new child calls. This only matters for the first read, because
  52. * once a message comes in the child call becomes committed and there will
  53. * be no new child calls.
  54. */
  55. private readStarted;
  56. private transparentRetryUsed;
  57. /**
  58. * Number of attempts so far
  59. */
  60. private attempts;
  61. private hedgingTimer;
  62. private committedCallIndex;
  63. private initialRetryBackoffSec;
  64. private nextRetryBackoffSec;
  65. private startTime;
  66. private maxAttempts;
  67. constructor(channel: InternalChannel, callConfig: CallConfig, methodName: string, host: string, credentials: CallCredentials, deadline: Deadline, callNumber: number, bufferTracker: MessageBufferTracker, retryThrottler?: RetryThrottler | undefined);
  68. getDeadlineInfo(): string[];
  69. getCallNumber(): number;
  70. private trace;
  71. private reportStatus;
  72. cancelWithStatus(status: Status, details: string): void;
  73. getPeer(): string;
  74. private getBufferEntry;
  75. private getNextBufferIndex;
  76. private clearSentMessages;
  77. private commitCall;
  78. private commitCallWithMostMessages;
  79. private isStatusCodeInList;
  80. private getNextRetryBackoffMs;
  81. private maybeRetryCall;
  82. private countActiveCalls;
  83. private handleProcessedStatus;
  84. private getPushback;
  85. private handleChildStatus;
  86. private maybeStartHedgingAttempt;
  87. private maybeStartHedgingTimer;
  88. private startNewAttempt;
  89. start(metadata: Metadata, listener: InterceptingListener): void;
  90. private handleChildWriteCompleted;
  91. private sendNextChildMessage;
  92. sendMessageWithContext(context: MessageContext, message: Buffer): void;
  93. startRead(): void;
  94. halfClose(): void;
  95. setCredentials(newCredentials: CallCredentials): void;
  96. getMethod(): string;
  97. getHost(): string;
  98. }