-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed test_mt and made TCPClient threadsafe #83
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
#include "utils/utils.h" | ||
#include "common/Future.h" | ||
#include "common/Exception.h" | ||
#include "common/Synchronization.h" | ||
|
||
namespace cirrus { | ||
|
||
|
@@ -103,15 +104,18 @@ cirrus::Future TCPClient::write_async(ObjectID oid, const void* data, | |
auto msg_contents = message::TCPBladeMessage::CreateWrite(*builder, | ||
oid, | ||
data_fb_vector); | ||
curr_txn_id_lock.wait(); | ||
const int txn_id = curr_txn_id++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I understand, you use a map txn_id->txn_info to keep the state of a put/get operation. This is necessary because our network layer works as an event handler. I think this needs to be briefly explained in the code. Probably in a comment to |
||
curr_txn_id_lock.signal(); | ||
auto msg = message::TCPBladeMessage::CreateTCPBladeMessage( | ||
*builder, | ||
curr_txn_id, | ||
txn_id, | ||
0, | ||
message::TCPBladeMessage::Message_Write, | ||
msg_contents.Union()); | ||
builder->Finish(msg); | ||
|
||
return enqueue_message(builder); | ||
return enqueue_message(builder, txn_id); | ||
} | ||
|
||
/** | ||
|
@@ -134,15 +138,19 @@ cirrus::Future TCPClient::read_async(ObjectID oid, void* data, | |
// Create and send read request | ||
auto msg_contents = message::TCPBladeMessage::CreateRead(*builder, oid); | ||
|
||
curr_txn_id_lock.wait(); | ||
const int txn_id = curr_txn_id++; | ||
curr_txn_id_lock.signal(); | ||
|
||
auto msg = message::TCPBladeMessage::CreateTCPBladeMessage( | ||
*builder, | ||
curr_txn_id, | ||
txn_id, | ||
0, | ||
message::TCPBladeMessage::Message_Read, | ||
msg_contents.Union()); | ||
builder->Finish(msg); | ||
|
||
return enqueue_message(builder, data); | ||
return enqueue_message(builder, txn_id, data); | ||
} | ||
|
||
/** | ||
|
@@ -191,15 +199,19 @@ bool TCPClient::remove(ObjectID oid) { | |
// Create and send removal request | ||
auto msg_contents = message::TCPBladeMessage::CreateRemove(*builder, oid); | ||
|
||
curr_txn_id_lock.wait(); | ||
const int txn_id = curr_txn_id++; | ||
curr_txn_id_lock.signal(); | ||
|
||
auto msg = message::TCPBladeMessage::CreateTCPBladeMessage( | ||
*builder, | ||
curr_txn_id, | ||
txn_id, | ||
0, | ||
message::TCPBladeMessage::Message_Remove, | ||
msg_contents.Union()); | ||
builder->Finish(msg); | ||
|
||
cirrus::Future future = enqueue_message(builder); | ||
cirrus::Future future = enqueue_message(builder, txn_id); | ||
return future.get(); | ||
} | ||
|
||
|
@@ -424,7 +436,7 @@ void TCPClient::process_send() { | |
*/ | ||
cirrus::Future TCPClient::enqueue_message( | ||
std::shared_ptr<flatbuffers::FlatBufferBuilder> builder, | ||
void *ptr) { | ||
const int txn_id, void *ptr) { | ||
std::shared_ptr<struct txn_info> txn = std::make_shared<struct txn_info>(); | ||
|
||
txn->mem_for_read = ptr; | ||
|
@@ -433,7 +445,7 @@ cirrus::Future TCPClient::enqueue_message( | |
map_lock.wait(); | ||
|
||
// Add to map | ||
txn_map[curr_txn_id++] = txn; | ||
txn_map[txn_id] = txn; | ||
|
||
// Release lock on map | ||
map_lock.signal(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import subprocess | ||
import time | ||
import test_runner | ||
|
||
# Set name of test to run | ||
testPath = "./tests/object_store/test_mt" | ||
# Call script to run the test | ||
test_runner.runTest(testPath) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this. There are atomic types in C++
http://en.cppreference.com/w/cpp/atomic/atomic