Skip to content

Commit

Permalink
fix: repair stream store self-interference problem
Browse files Browse the repository at this point in the history
The stream store API evolved since the read/write mode interlock logic was
originally coded, such each write has become a singular, stand-alone
operation. The read/write mode interlock logic was thus overly aggressive in the
face of read-after-write use cases, breaking some uses, notably the problem
raised in issue #3437 as well as the swingset-runner "dump after each crank"
debug feature.  This fixes that.
  • Loading branch information
FUDCo committed Jun 30, 2021
1 parent 1e8d630 commit 948d837
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 19 deletions.
3 changes: 1 addition & 2 deletions packages/swing-store-lmdb/src/sqlStreamStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ export function sqlStreamStore(dbDir, io) {
insistStreamPosition(position);

assert(
[undefined, 'writing'].includes(streamStatus.get(streamName)),
!streamStatus.get(streamName),
X`can't write stream ${q(streamName)} because it's already in use`,
);
streamStatus.set(streamName, 'writing');

db.prepare(
`
Expand Down
4 changes: 0 additions & 4 deletions packages/swing-store-lmdb/test/test-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ test('streamStore mode interlock', t => {
const start = streamStore.STREAM_START;

const s1pos = streamStore.writeStreamItem('st1', 'first', start);

t.throws(() => streamStore.readStream('st1', start, s1pos), {
message: `can't read stream "st1" because it's already in use`,
});
streamStore.closeStream('st1');

const reader = streamStore.readStream('st1', start, s1pos);
Expand Down
14 changes: 4 additions & 10 deletions packages/swing-store-simple/src/simpleSwingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,12 @@ export function initSimpleSwingStore() {
let stream = streams.get(streamName);
if (!stream) {
stream = [];
streamStatus.set(streamName, 'write');
streams.set(streamName, stream);
} else {
const status = streamStatus.get(streamName);
if (!status) {
streamStatus.set(streamName, 'write');
} else {
assert(
status === 'write',
X`can't write stream ${q(streamName)} because it's already in use`,
);
}
assert(
!streamStatus.get(streamName),
X`can't write stream ${q(streamName)} because it's already in use`,
);
}
stream[position.itemCount] = item;
return harden({ itemCount: position.itemCount + 1 });
Expand Down
3 changes: 0 additions & 3 deletions packages/swing-store-simple/test/test-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ test('streamStore mode interlock', t => {

const s1pos = streamStore.writeStreamItem('st1', 'first', start);

t.throws(() => streamStore.readStream('st1', start, s1pos), {
message: `can't read stream "st1" because it's already in use`,
});
streamStore.closeStream('st1');

const reader = streamStore.readStream('st1', start, s1pos);
Expand Down

0 comments on commit 948d837

Please sign in to comment.