Skip to content

feat: Implement ReadTransaction class and integrate with Client and Replica - #83

Merged
Tech-Matt merged 7 commits into
mainfrom
feat/readTransaction
Aug 28, 2026
Merged

feat: Implement ReadTransaction class and integrate with Client and Replica#83
Tech-Matt merged 7 commits into
mainfrom
feat/readTransaction

Conversation

@alanmasu

@alanmasu alanmasu commented Aug 16, 2026

Copy link
Copy Markdown
Owner

scheduleTransaction(transaction);
}

public void onReadMsg(ReadMsg msg) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onReadMsg() directly accesses positions[msg.index], bypassing the bounds validation already provided by getPosition(). An invalid index can therefore throw an exception inside the actor.

Possible mitigations

Use getPosition(msg.index) or validate the index explicitly. The protocol should also define how an invalid read is reported, instead of allowing the actor to fail.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good catch!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it, but now may that an unaware Client may throws an exception on a Replica without noticing it.

Should we implement a fallback Transaction.ErrorMsg to tell the client that the index it asked for is unavailable? (same could be for the WriteTransaction)

If yes, please add a follow-up Issue connected to this comment please!

Comment thread src/test/java/it/unitn/ds/regression/TestReadTransaction.java
Comment thread src/test/java/it/unitn/ds/regression/TestReadTransaction.java
Comment on lines +48 to +55
public static class ReadResultMsg extends Msg {
public final int replicaId;
public final int value;

public ReadResultMsg(TransactionId transactionId, EpochPair epochPair, ActorRef sender, int value, int replicaId) {
super(transactionId, epochPair, sender);
this.replicaId = replicaId;
this.value = value;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadResultMsg.sender already identifies the responding replica as an ActorRef, while replicaId carries a second identity for the same replica. These two values could theoretically disagree.

Possible mitigations

Remove replicaId from the internal message and use sender. If it remains, replica IDs should be validated as unique during system initialization, and maybe they can just be derived on the Client side from their ActorRef, with some method like getReplicaIdFromActorRef() or something similar.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe they can just be derived on the Client side from their ActorRef, with some method like getReplicaIdFromActorRef() or something similar.

No, is not possible. The replicaId is an integer that could not be retriven from the ActorRef point of view, and yes, it could disagree with the ActorRef, but there is no other way to get the Replica.id value needed for populate the AbstractClient.ReadResult.fromReplica

And this is the cause that drive me in not sending a "negative result" (ReadResult.success = false), basically you don't have the replica number yet if no message response is received and there is no other way to get it.

Tell me if I'm wrong...

@Tech-Matt

Copy link
Copy Markdown
Collaborator

Also added #93 as a new issue.

@alanmasu alanmasu left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the issue you rise.

Comment on lines +48 to +55
public static class ReadResultMsg extends Msg {
public final int replicaId;
public final int value;

public ReadResultMsg(TransactionId transactionId, EpochPair epochPair, ActorRef sender, int value, int replicaId) {
super(transactionId, epochPair, sender);
this.replicaId = replicaId;
this.value = value;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe they can just be derived on the Client side from their ActorRef, with some method like getReplicaIdFromActorRef() or something similar.

No, is not possible. The replicaId is an integer that could not be retriven from the ActorRef point of view, and yes, it could disagree with the ActorRef, but there is no other way to get the Replica.id value needed for populate the AbstractClient.ReadResult.fromReplica

And this is the cause that drive me in not sending a "negative result" (ReadResult.success = false), basically you don't have the replica number yet if no message response is received and there is no other way to get it.

Tell me if I'm wrong...

scheduleTransaction(transaction);
}

public void onReadMsg(ReadMsg msg) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good catch!

scheduleTransaction(transaction);
}

public void onReadMsg(ReadMsg msg) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it, but now may that an unaware Client may throws an exception on a Replica without noticing it.

Should we implement a fallback Transaction.ErrorMsg to tell the client that the index it asked for is unavailable? (same could be for the WriteTransaction)

If yes, please add a follow-up Issue connected to this comment please!

Comment thread src/test/java/it/unitn/ds/regression/TestReadTransaction.java
Comment thread src/test/java/it/unitn/ds/regression/TestReadTransaction.java
@alanmasu
alanmasu requested a review from Tech-Matt August 24, 2026 13:03
Comment thread src/test/java/it/unitn/ds/regression/TestReadTransaction.java

@alanmasu alanmasu left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved

Comment thread src/test/java/it/unitn/ds/regression/TestReadTransaction.java
@alanmasu
alanmasu requested a review from Tech-Matt August 27, 2026 11:43
@Tech-Matt
Tech-Matt merged commit df91bf4 into main Aug 28, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In review to Done in Distributed Systems Project Aug 28, 2026
Tech-Matt added a commit that referenced this pull request Aug 28, 2026
Integrate PR #83 read-transaction changes and resolve the Replica overlap by retaining both ReadMsg and UpdateMsg receive registrations and handlers. Focused read and update tests pass together after the resolution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Implement the FSM [ReadTransaction]

2 participants