• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HDFGroup / hermes / 4835209237

pending completion
4835209237

Pull #515

github

GitHub
Merge cf4fc1161 into 87672e106
Pull Request #515: v1.0

5502 of 5502 new or added lines in 117 files covered. (100.0%)

4997 of 7300 relevant lines covered (68.45%)

6168020.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.37
/src/api/hermes.cc
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Distributed under BSD 3-Clause license.                                   *
3
 * Copyright by The HDF Group.                                               *
4
 * Copyright by the Illinois Institute of Technology.                        *
5
 * All rights reserved.                                                      *
6
 *                                                                           *
7
 * This file is part of Hermes. The full Hermes copyright notice, including  *
8
 * terms governing use, modification, and redistribution, is contained in    *
9
 * the COPYING file, which can be found at the top directory. If you do not  *
10
 * have access to the file, you may request a copy from help@hdfgroup.org.   *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12

13
#include "hermes.h"
14
#include "bucket.h"
15

16
namespace hermes::api {
17

18
/**====================================
19
 * PRIVATE Init + Finalize Operations
20
 * ===================================*/
21

22
/** Internal initialization of Hermes */
23
void Hermes::Init(HermesType mode,
105✔
24
                  std::string server_config_path,
25
                  std::string client_config_path) {
26
  // Initialize hermes
27
  hshm::ScopedMutex lock(lock_, 1);
105✔
28
  if (is_initialized_) {
105✔
29
    return;
×
30
  }
31
  mode_ = mode;
105✔
32
  is_being_initialized_ = true;
105✔
33
  switch (mode_) {
105✔
34
    case HermesType::kServer: {
28✔
35
      InitServer(std::move(server_config_path));
56✔
36
      break;
28✔
37
    }
38
    case HermesType::kClient: {
77✔
39
      InitClient(std::move(server_config_path),
308✔
40
                 std::move(client_config_path));
77✔
41
      break;
77✔
42
    }
43
    case HermesType::kNone: {
×
44
      HELOG(kFatal, "Cannot have none HermesType")
×
45
    }
46
  }
47
  is_initialized_ = true;
105✔
48
  is_being_initialized_ = false;
105✔
49
}
50

51
/** Initialize Hermes as a server */
52
void Hermes::InitServer(std::string server_config_path) {
28✔
53
  HERMES_THREAD_MODEL->SetThreadModel(hshm::ThreadType::kArgobots);
28✔
54
  LoadServerConfig(server_config_path);
28✔
55
  InitSharedMemory();
28✔
56

57
  // Initialize RPC
58
  rpc_.InitServer();
28✔
59
  rpc_.InitClient();
28✔
60

61
  // Load the trait libraries
62
  traits_.Init();
28✔
63

64
  // Construct the reference objects
65
  mdm_.shm_init(header_->mdm_, main_alloc_, &server_config_);
28✔
66
  rpc_.InitClient();
28✔
67
  bpm_.shm_init(header_->bpm_, main_alloc_);
28✔
68
  borg_.shm_init(header_->borg_, main_alloc_);
28✔
69
  prefetch_.Init();
28✔
70
}
28✔
71

72
/** Initialize Hermes as a client to the daemon */
73
void Hermes::InitClient(std::string server_config_path,
77✔
74
                        std::string client_config_path) {
75
  LoadServerConfig(server_config_path);
77✔
76
  LoadClientConfig(client_config_path);
77✔
77
  LoadSharedMemory();
77✔
78

79
  // Initialize references to SHM types
80
  mdm_.shm_deserialize(header_->mdm_);
77✔
81
  rpc_.InitClient();
77✔
82
  bpm_.shm_deserialize(header_->bpm_);
77✔
83
  borg_.shm_deserialize(header_->borg_);
77✔
84
  prefetch_.Init();
77✔
85
  // mdm_.PrintDeviceInfo();
86

87
  // Load the trait libraries
88
  traits_.Init();
77✔
89
}
77✔
90

91
/** Load the server-side configuration */
92
void Hermes::LoadServerConfig(std::string config_path) {
105✔
93
  if (config_path.size() == 0) {
105✔
94
    config_path = GetEnvSafe(kHermesServerConf);
105✔
95
  }
96
  if (mode_ == HermesType::kServer) {
105✔
97
    HILOG(kInfo, "Loading server configuration: {}", config_path)
28✔
98
  }
99
  server_config_.LoadFromFile(config_path);
105✔
100
}
105✔
101

102
/** Load the client-side configuration */
103
void Hermes::LoadClientConfig(std::string config_path) {
77✔
104
  if (config_path.size() == 0) {
77✔
105
    config_path = GetEnvSafe(kHermesClientConf);
77✔
106
  }
107
  // HILOG(kInfo, "Loading client configuration: {}", config_path)
108
  client_config_.LoadFromFile(config_path);
77✔
109
}
77✔
110

111
/** Initialize shared-memory between daemon and client */
112
void Hermes::InitSharedMemory() {
28✔
113
  // Create shared-memory allocator
114
  auto mem_mngr = HERMES_MEMORY_MANAGER;
28✔
115
  mem_mngr->CreateBackend<hipc::PosixShmMmap>(
28✔
116
      hipc::MemoryManager::GetDefaultBackendSize(),
117
      server_config_.shmem_name_);
28✔
118
  main_alloc_ =
56✔
119
      mem_mngr->CreateAllocator<hipc::ScalablePageAllocator>(
28✔
120
          server_config_.shmem_name_,
121
          main_alloc_id,
122
          sizeof(HermesShm));
123
  header_ = main_alloc_->GetCustomHeader<HermesShm>();
28✔
124
}
28✔
125

126
/** Connect to a Daemon's shared memory */
127
void Hermes::LoadSharedMemory() {
77✔
128
  // Load shared-memory allocator
129
  auto mem_mngr = HERMES_MEMORY_MANAGER;
77✔
130
  mem_mngr->AttachBackend(hipc::MemoryBackendType::kPosixShmMmap,
77✔
131
                          server_config_.shmem_name_);
77✔
132
  main_alloc_ = mem_mngr->GetAllocator(main_alloc_id);
77✔
133
  header_ = main_alloc_->GetCustomHeader<HermesShm>();
77✔
134
}
77✔
135

136
/** Finalize Daemon mode */
137
void Hermes::FinalizeServer() {
28✔
138
  // NOTE(llogan): rpc_.Finalize() is called internally by daemon in this case
139
  // bpm_.shm_destroy();
140
  // mdm_.shm_destroy();
141
}
28✔
142

143
/** Finalize client mode */
144
void Hermes::FinalizeClient() {
77✔
145
  if (client_config_.stop_daemon_) {
77✔
146
    StopDaemon();
28✔
147
  }
148
  rpc_.Finalize();
77✔
149
}
77✔
150

151
/**====================================
152
 * PUBLIC Finalize Operations
153
 * ===================================*/
154

155
/** Finalize Hermes explicitly */
156
void Hermes::Finalize() {
184✔
157
  if (!is_initialized_ || is_terminated_) {
184✔
158
    return;
159
  }
160
  switch (mode_) {
105✔
161
    case HermesType::kServer: {
28✔
162
      FinalizeServer();
28✔
163
      break;
28✔
164
    }
165
    case HermesType::kClient: {
77✔
166
      FinalizeClient();
77✔
167
      break;
77✔
168
    }
169
    default: {
×
170
      throw std::logic_error("Invalid HermesType to launch in");
×
171
    }
172
  }
173
  is_initialized_ = false;
105✔
174
  is_terminated_ = true;
105✔
175
}
176

177
/** Run the Hermes core Daemon */
178
void Hermes::RunDaemon() {
28✔
179
  rpc_.RunDaemon();
28✔
180
}
28✔
181

182
/** Stop the Hermes core Daemon */
183
void Hermes::StopDaemon() {
28✔
184
  rpc_.StopDaemon();
28✔
185
}
28✔
186

187
/**====================================
188
 * PUBLIC Bucket Operations
189
 * ===================================*/
190

191
/** Get or create a Bucket in Hermes */
192
Bucket Hermes::GetBucket(std::string name,
2,400✔
193
                         Context ctx,
194
                         size_t backend_size) {
195
  return Bucket(name, ctx, backend_size);
2,400✔
196
}
197

198
/** Get an existing Bucket in Hermes */
199
Bucket Hermes::GetBucket(TagId tag_id) {
3,105✔
200
  return Bucket(tag_id);
3,105✔
201
}
202

203
/**====================================
204
 * PUBLIC I/O Operations
205
 * ===================================*/
206

207
/** Waits for all blobs to finish being flushed */
208
void Hermes::Flush() {
3,304✔
209
  borg_.GlobalWaitForFullFlush();
3,304✔
210
}
3,304✔
211

212
/** Destroy all buckets and blobs in this instance */
213
void Hermes::Clear() {
891✔
214
  Flush();
891✔
215
  mdm_.GlobalClear();
891✔
216
}
891✔
217

218
/**====================================
219
 * PUBLIC Tag Operations
220
 * ===================================*/
221

222
/** Locate all blobs with a tag */
223
std::vector<BlobId> Hermes::GroupBy(TagId tag_id) {
1✔
224
  return mdm_.GlobalGroupByTag(tag_id);
1✔
225
}
226

227

228

229
}  // namespace hermes::api
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc