diff --git a/CHANGELOG.md b/CHANGELOG.md index e5563813..af5face7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased] +### Bug fixes + +- Fixed a bug: the timeout in IProtoBegin was being specified in milliseconds (as a `long`), but + the [protocol](https://www.tarantool.io/ru/doc/latest/reference/internals/iproto/streams/#iproto-begin) + requires the timeout to be passed in seconds (as a `double`). + ## [1.7.2] - 2026-09-25 ### Client diff --git a/tarantool-core/src/main/java/io/tarantool/core/protocol/requests/IProtoBegin.java b/tarantool-core/src/main/java/io/tarantool/core/protocol/requests/IProtoBegin.java index 76ce959c..d5f834ef 100644 --- a/tarantool-core/src/main/java/io/tarantool/core/protocol/requests/IProtoBegin.java +++ b/tarantool-core/src/main/java/io/tarantool/core/protocol/requests/IProtoBegin.java @@ -27,14 +27,14 @@ public class IProtoBegin extends IProtoBaseRequest { // body fields - private final long timeout; + private final double timeoutS; private final TransactionIsolationLevel level; - public IProtoBegin(Long streamId, long timeout, TransactionIsolationLevel level) { - if (timeout <= 0) { - throw new IllegalArgumentException("timeout should be greater than 0"); + public IProtoBegin(Long streamId, long timeoutMs, TransactionIsolationLevel level) { + if (timeoutMs <= 0) { + throw new IllegalArgumentException("timeoutMs should be greater than 0"); } - this.timeout = timeout; + this.timeoutS = timeoutMs / 1_000d; this.level = level; this.setStreamId(streamId); } @@ -55,7 +55,7 @@ public byte[] getPacket(MessageBufferPacker packer) throws IOException { } packer.addPayload(RAW_IPROTO_TIMEOUT); // key - packer.packDouble(timeout); // value + packer.packDouble(timeoutS); // value if (!level.equals(TransactionIsolationLevel.DEFAULT)) { packer.addPayload(RAW_IPROTO_TXN_ISOLATION); // key @@ -68,7 +68,7 @@ public byte[] getPacket(MessageBufferPacker packer) throws IOException { @Override public MapValue getBody() { Map map = new HashMap<>(); - map.put(MP_IPROTO_TIMEOUT, ValueFactory.newInteger(timeout)); + map.put(MP_IPROTO_TIMEOUT, ValueFactory.newFloat(timeoutS)); if (!level.equals(TransactionIsolationLevel.DEFAULT)) { map.put(MP_IPROTO_TXN_ISOLATION, ValueFactory.newInteger(level.ordinal())); @@ -94,8 +94,8 @@ public String toString() { .append("IProtoBegin(syncId = ") .append(getSyncId()) .append(", timeout = ") - .append(timeout) - .append(", level = ") + .append(timeoutS) + .append("s, level = ") .append(level) .append(")"); } diff --git a/tarantool-core/src/test/java/io/tarantool/core/unit/requests/RequestTest.java b/tarantool-core/src/test/java/io/tarantool/core/unit/requests/RequestTest.java index 70877034..c9499019 100644 --- a/tarantool-core/src/test/java/io/tarantool/core/unit/requests/RequestTest.java +++ b/tarantool-core/src/test/java/io/tarantool/core/unit/requests/RequestTest.java @@ -60,14 +60,15 @@ public void testRequestsToString() { // begin final Long streamId = 1L; - long timeout = 1L; - IProtoRequest begin = new IProtoBegin(streamId, timeout, TransactionIsolationLevel.DEFAULT); + long timeoutMs = 1L; + double timeoutS = timeoutMs / 1_000d; + IProtoRequest begin = new IProtoBegin(streamId, timeoutMs, TransactionIsolationLevel.DEFAULT); assertEquals( "IProtoBegin(syncId = " + begin.getSyncId() + ", timeout = " - + timeout - + ", level = " + + timeoutS + + "s, level = " + TransactionIsolationLevel.DEFAULT + ")", begin.toString());