@platformatic/kafka 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1248,9 +1248,7 @@ export class Consumer extends Base {
1248
1248
  .appendArray(assignments, (w, { topic, partitions }) => {
1249
1249
  w.appendString(topic, false).appendArray(partitions, (w, a) => w.appendInt32(a), false, false);
1250
1250
  }, false, false);
1251
- if (userData) {
1252
- writer.append(userData);
1253
- }
1251
+ writer.appendBytes(userData ?? null, false);
1254
1252
  return writer.buffer;
1255
1253
  }
1256
1254
  #decodeProtocolAssignment(buffer) {
@@ -2,7 +2,7 @@ import { Readable } from 'node:stream';
2
2
  import { createPromisifiedCallback, kCallbackPromise, noopCallback } from "../../apis/callbacks.js";
3
3
  import { ListOffsetTimestamps } from "../../apis/enumerations.js";
4
4
  import { consumerReceivesChannel, createDiagnosticContext, notifyCreation } from "../../diagnostic.js";
5
- import { UserError } from "../../errors.js";
5
+ import { protocolErrors, UserError } from "../../errors.js";
6
6
  import { IS_CONTROL } from "../../protocol/records.js";
7
7
  import { runAsyncSeries } from "../../registries/abstract.js";
8
8
  import { kAutocommit, kInstance, kRefreshOffsetsAndFetch } from "../../symbols.js";
@@ -407,6 +407,13 @@ export class MessagesStream extends Readable {
407
407
  this.push(null);
408
408
  return;
409
409
  }
410
+ if (this.#fallbackMode !== MessagesStreamFallbackModes.FAIL &&
411
+ this.#handleOffsetOutOfRange(error, topicIds)) {
412
+ process.nextTick(() => {
413
+ this.#fetch();
414
+ });
415
+ return;
416
+ }
410
417
  this.destroy(error);
411
418
  return;
412
419
  }
@@ -423,6 +430,43 @@ export class MessagesStream extends Readable {
423
430
  }
424
431
  });
425
432
  }
433
+ #handleOffsetOutOfRange(error, topicIds) {
434
+ if (!error.findBy?.('apiId', 'OFFSET_OUT_OF_RANGE')) {
435
+ return false;
436
+ }
437
+ const response = error.response;
438
+ if (!response || response.errorCode !== 0) {
439
+ return false;
440
+ }
441
+ const recoveredOffsets = [];
442
+ for (const topicResponse of response.responses) {
443
+ const topic = topicIds.get(topicResponse.topicId);
444
+ if (!topic) {
445
+ return false;
446
+ }
447
+ for (const partitionResponse of topicResponse.partitions) {
448
+ if (partitionResponse.errorCode === 0) {
449
+ continue;
450
+ }
451
+ if (partitionResponse.errorCode !== protocolErrors.OFFSET_OUT_OF_RANGE.code) {
452
+ return false;
453
+ }
454
+ const key = `${topic}:${partitionResponse.partitionIndex}`;
455
+ const offset = this.#fallbackMode === MessagesStreamFallbackModes.EARLIEST
456
+ ? partitionResponse.logStartOffset
457
+ : partitionResponse.highWatermark;
458
+ recoveredOffsets.push([key, offset]);
459
+ }
460
+ }
461
+ for (const [key, offset] of recoveredOffsets) {
462
+ this.#offsetsToFetch.set(key, offset);
463
+ this.#offsetsCommitted.set(key, offset);
464
+ }
465
+ if (recoveredOffsets.length > 0) {
466
+ this.emit('offsets');
467
+ }
468
+ return recoveredOffsets.length > 0;
469
+ }
426
470
  #pushRecords(metadata, topicIds, response, requestedOffsets) {
427
471
  const autocommit = this.#autocommitEnabled;
428
472
  const keyDeserializer = this.#keyDeserializer;
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = "@platformatic/kafka";
2
- export const version = "2.0.0";
2
+ export const version = "2.0.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/kafka",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Modern and performant client for Apache Kafka",
5
5
  "homepage": "https://github.com/platformatic/kafka",
6
6
  "author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",