Skip to content

Commit bee23ae

Browse files
Partial state flag (#160)
* Update contract * Remove flag parsing, replace with StartMessage.partial_state field
1 parent 411be14 commit bee23ae

File tree

8 files changed

+14
-45
lines changed

8 files changed

+14
-45
lines changed

proto/protocol.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ message StartMessage {
4040

4141
// protolint:disable:next REPEATED_FIELD_NAMES_PLURALIZED
4242
repeated StateEntry state_map = 4;
43+
bool partial_state = 5;
4344
}
4445

4546
// Type: 0x0000 + 1

src/invocation.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ export class InvocationBuilder<I, O> implements RestateStreamConsumer {
5757
switch (this.state) {
5858
case State.ExpectingStart:
5959
checkState(State.ExpectingStart, START_MESSAGE_TYPE, m);
60-
this.handleStartMessage(
61-
m.message as StartMessage,
62-
m.partialStateFlag || false
63-
);
60+
this.handleStartMessage(m.message as StartMessage);
6461
this.state = State.ExpectingInput;
6562
return false;
6663

@@ -114,14 +111,11 @@ export class InvocationBuilder<I, O> implements RestateStreamConsumer {
114111
return this.complete.promise;
115112
}
116113

117-
private handleStartMessage(
118-
m: StartMessage,
119-
partialState: boolean
120-
): InvocationBuilder<I, O> {
114+
private handleStartMessage(m: StartMessage): InvocationBuilder<I, O> {
121115
this.nbEntriesToReplay = m.knownEntries;
122116
this.id = m.id;
123117
this.debugId = m.debugId;
124-
this.localStateStore = new LocalStateStore(partialState, m.stateMap);
118+
this.localStateStore = new LocalStateStore(m.partialState, m.stateMap);
125119
return this;
126120
}
127121

src/io/decoder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ function decodeMessages(decoderState: DecoderState, out: Output): DecoderState {
8585
message,
8686
header.completedFlag,
8787
header.protocolVersion,
88-
header.requiresAckFlag,
89-
header.partialStateFlag
88+
header.requiresAckFlag
9089
)
9190
);
9291
}

src/io/encoder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ export function encodeMessage(msg: Message): Uint8Array {
4141
bodyBuf.length,
4242
msg.completed,
4343
msg.protocolVersion, // only set for incoming start message
44-
msg.requiresAck,
45-
msg.partialStateFlag
44+
msg.requiresAck
4645
);
4746
const headerBuf = Buffer.alloc(8);
4847
const encoded = header.toU64be();

src/types/types.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export class Message {
2525
readonly message: ProtocolMessage,
2626
readonly completed?: boolean,
2727
readonly protocolVersion?: number,
28-
readonly requiresAck?: boolean,
29-
readonly partialStateFlag?: boolean
28+
readonly requiresAck?: boolean
3029
) {}
3130
}
3231

@@ -54,10 +53,6 @@ class MessageType {
5453
return messageType == START_MESSAGE_TYPE;
5554
}
5655

57-
static hasPartialStateFlag(messageType: bigint): boolean {
58-
return messageType == START_MESSAGE_TYPE;
59-
}
60-
6156
static isCustom(messageTypeId: bigint): boolean {
6257
return !KNOWN_MESSAGE_TYPES.has(messageTypeId);
6358
}
@@ -71,7 +66,6 @@ const CUSTOM_MESSAGE_MASK = BigInt(0xfc00);
7166
const COMPLETED_MASK = BigInt(0x0001_0000_0000);
7267
const VERSION_MASK = BigInt(0x03ff_0000_0000);
7368
const REQUIRES_ACK_MASK = BigInt(0x0001_0000_0000);
74-
const PARTIAL_STATE_MASK = BigInt(0x0400_0000_0000);
7569

7670
// The header is exported but only for tests.
7771
export class Header {
@@ -101,20 +95,14 @@ export class Header {
10195
(value & REQUIRES_ACK_MASK) !== 0n
10296
? true
10397
: undefined;
104-
const partialStateFlag =
105-
MessageType.hasPartialStateFlag(messageType) &&
106-
(value & PARTIAL_STATE_MASK) !== 0n
107-
? true
108-
: undefined;
10998
const frameLength = Number(value & 0xffffffffn);
11099

111100
return new Header(
112101
messageType,
113102
frameLength,
114103
completedFlag,
115104
protocolVersion,
116-
requiresAckFlag,
117-
partialStateFlag
105+
requiresAckFlag
118106
);
119107
}
120108

@@ -129,9 +117,6 @@ export class Header {
129117
if (this.requiresAckFlag) {
130118
res = res | REQUIRES_ACK_MASK;
131119
}
132-
if (this.partialStateFlag) {
133-
res = res | PARTIAL_STATE_MASK;
134-
}
135120
return res;
136121
}
137122
}

test/protocol_stream.test.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ describe("Header", () => {
3535

3636
it("invoke_test", () => roundtripTest(newStart(1, 25)));
3737

38-
it("invoke_test_partial_state", () => roundtripTest(newStart(1, 25, true)));
39-
it("invoke_test_complete_state", () =>
40-
roundtripTest(newStart(1, 25, undefined)));
41-
4238
it("completion_test", () =>
4339
roundtripTest(newHeader(COMPLETION_MESSAGE_TYPE, 22)));
4440

@@ -187,18 +183,13 @@ function newHeader(messageTypeId: bigint, length: number): Header {
187183
return new Header(messageTypeId, length);
188184
}
189185

190-
function newStart(
191-
protocolVersion: number,
192-
length: number,
193-
partialStateFlag?: boolean
194-
): Header {
186+
function newStart(protocolVersion: number, length: number): Header {
195187
return new Header(
196188
START_MESSAGE_TYPE,
197189
length,
198190
undefined,
199191
protocolVersion,
200-
undefined,
201-
partialStateFlag
192+
undefined
202193
);
203194
}
204195

test/protoutils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export function startMessage(
6969
debugId: "123",
7070
knownEntries: knownEntries, // only used for the Lambda case. For bidi streaming, this will be imputed by the testdriver
7171
stateMap: toStateEntries(state || []),
72+
partialState: partialState !== false,
7273
}),
7374
undefined,
7475
0,
75-
undefined,
76-
partialState === false ? undefined : true
76+
undefined
7777
);
7878
}
7979

test/testdriver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ export class TestDriver<I, O> implements Connection {
8585
debugId: startEntry.debugId,
8686
knownEntries: endOfReplay - 1,
8787
stateMap: startEntry.stateMap,
88+
partialState: startEntry.partialState,
8889
}),
8990
msg.completed,
9091
msg.protocolVersion,
91-
msg.requiresAck,
92-
msg.partialStateFlag
92+
msg.requiresAck
9393
);
9494

9595
const replayMessages = entries.slice(0, endOfReplay);

0 commit comments

Comments
 (0)