-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1193 from Expensify/main
Update expensify_prod branch
- Loading branch information
Showing
22 changed files
with
200 additions
and
44 deletions.
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
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
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,71 @@ | ||
#include <BedrockCommand.h> | ||
#include <sqlitecluster/SQLiteClusterMessenger.h> | ||
#include <sqlitecluster/SQLiteNode.h> | ||
|
||
SQLiteClusterMessenger::SQLiteClusterMessenger(shared_ptr<SQLiteNode>& node) | ||
: _node(node) | ||
{ | ||
} | ||
|
||
bool SQLiteClusterMessenger::sendToLeader(BedrockCommand& command) { | ||
string leaderAddress; | ||
auto _nodeCopy = atomic_load(&_node); | ||
if (_nodeCopy) { | ||
for (SQLiteNode::Peer* peer : _nodeCopy->peerList) { | ||
if (peer->state == STCPNode::LEADING && !peer->commandAddress.load().empty()) { | ||
leaderAddress = peer->commandAddress; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// SParseURI expects a typical http or https scheme. | ||
string url = "http://" + leaderAddress; | ||
string host, path; | ||
if (!SParseURI(url, host, path) || !SHostIsValid(host)) { | ||
return false; | ||
} | ||
|
||
// Create a new transaction. This can throw if `validate` fails. We explicitly do this *before* creating a socket. | ||
Transaction* transaction = new Transaction(*this); | ||
|
||
// I don't trust this not to ever leak currently, but for the moment, this is OK. | ||
_transactionCommands[transaction] = make_pair(&command, STimeNow()); | ||
|
||
Socket* s = nullptr; | ||
try { | ||
s = new Socket(host, nullptr); | ||
} catch (const SException& exception) { | ||
_transactionCommands.erase(transaction); | ||
delete transaction; | ||
return false; | ||
} | ||
|
||
transaction->s = s; | ||
transaction->fullRequest = command.request.serialize(); | ||
|
||
command.httpsRequests.push_back(transaction); | ||
|
||
// Ship it. | ||
transaction->s->send(command.request.serialize()); | ||
|
||
return true; | ||
} | ||
|
||
bool SQLiteClusterMessenger::_onRecv(Transaction* transaction) | ||
{ | ||
transaction->response = getHTTPResponseCode(transaction->fullResponse.methodLine); | ||
auto cmdIt = _transactionCommands.find(transaction); | ||
if (cmdIt != _transactionCommands.end()) { | ||
BedrockCommand* command = cmdIt->second.first; | ||
command->response = transaction->fullResponse; | ||
command->response["escalationTime"] = to_string(STimeNow() - cmdIt->second.second); | ||
command->complete = true; | ||
_transactionCommands.erase(cmdIt); | ||
} | ||
return false; | ||
} | ||
|
||
bool SQLiteClusterMessenger::handleAllResponses() { | ||
return true; | ||
} |
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,20 @@ | ||
#include <libstuff/libstuff.h> | ||
#include <libstuff/SHTTPSManager.h> | ||
|
||
class SQLiteNode; | ||
class BedrockCommand; | ||
|
||
class SQLiteClusterMessenger : public SStandaloneHTTPSManager { | ||
public: | ||
SQLiteClusterMessenger(shared_ptr<SQLiteNode>& node); | ||
bool sendToLeader(BedrockCommand& command); | ||
virtual bool _onRecv(Transaction* transaction) override; | ||
|
||
virtual bool handleAllResponses() override; | ||
|
||
private: | ||
shared_ptr<SQLiteNode>& _node; | ||
|
||
// Map of transactions to their commands and escalation start times | ||
map<Transaction*, pair<BedrockCommand*, uint64_t>> _transactionCommands; | ||
}; |
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
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
Oops, something went wrong.