forked from falcon-transport/verbsmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverbsmarks_main.cc
More file actions
65 lines (59 loc) · 2.19 KB
/
Copy pathverbsmarks_main.cc
File metadata and controls
65 lines (59 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <iostream>
#include <string>
#include <thread>
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "absl/log/log.h"
#include "ibverbs_utils.h"
#include "utils.h"
#include "verbsmarks_binary.h"
#include "verbsmarks_binary_flags.h"
ABSL_FLAG(std::string, device_name, "", "RDMA device name");
int Run(verbsmarks::VerbsmarksBinary* const verbsmarks_binary) {
if (absl::GetFlag(FLAGS_is_leader)) {
// Runs as a leader.
auto status = verbsmarks_binary->CreateVerbsmarksLeaderAndStart();
if (!status.ok()) {
std::cout << "Verbsmarks leader fails: " << status << '\n';
LOG(ERROR) << "Verbsmarks leader fails: " << status;
return -1;
}
} else {
auto device_name = absl::GetFlag(FLAGS_device_name);
// Create a separate thread to handle AEs.
std::thread async_event_handler(
verbsmarks::ibverbs_utils::WaitAndAckAsyncEvents, device_name);
async_event_handler.detach();
// Runs as a follower.
auto status =
verbsmarks_binary->CreateVerbsmarksFollowerAndRun(device_name);
if (!status.ok()) {
std::cout << "Verbsmarks follower fails: " << status << '\n';
LOG(ERROR) << "verbsmarks follower fails: " << status;
return -1;
}
}
return 0;
}
int main(int argc, char** argv) {
absl::ParseCommandLine(argc, argv);
verbsmarks::VerbsmarksBinary verbsmarks_binary(
/*leader_creds=*/verbsmarks::utils::GetGrpcServerCredentials(),
/*follower_creds=*/verbsmarks::utils::GetGrpcServerCredentials(),
/*follower_client_creds=*/
verbsmarks::utils::GetGrpcChannelCredentials());
return Run(&verbsmarks_binary);
}