| 305 | }; |
| 306 | |
| 307 | UID getSharedMemoryMachineId() { |
| 308 | // new UID to use if an existing one is not found |
| 309 | UID newUID = deterministicRandom()->randomUniqueID(); |
| 310 | |
| 311 | #if DEBUG_DETERMINISM |
| 312 | // Don't use shared memory if DEBUG_DETERMINISM is set |
| 313 | return newUID; |
| 314 | #else |
| 315 | UID* machineId = nullptr; |
| 316 | int numTries = 0; |
| 317 | |
| 318 | // Permissions object defaults to 0644 on *nix, but on windows defaults to allowing access to only the creator. |
| 319 | // On windows, this means that we have to create an elaborate workaround for DACLs |
| 320 | WorldReadablePermissions p; |
| 321 | std::string sharedMemoryIdentifier = "fdbserver_shared_memory_id"; |
| 322 | loop { |
| 323 | try { |
| 324 | // "0" is the default netPrefix "addr" |
| 325 | boost::interprocess::managed_shared_memory segment( |
| 326 | boost::interprocess::open_or_create, sharedMemoryIdentifier.c_str(), 1000, 0, p.permission); |
| 327 | machineId = segment.find_or_construct<UID>("machineId")(newUID); |
| 328 | if (!machineId) |
| 329 | criticalError( |
| 330 | FDB_EXIT_ERROR, "SharedMemoryError", "Could not locate or create shared memory - 'machineId'"); |
| 331 | return *machineId; |
| 332 | } catch (boost::interprocess::interprocess_exception&) { |
| 333 | try { |
| 334 | // If the shared memory already exists, open it read-only in case it was created by another user |
| 335 | boost::interprocess::managed_shared_memory segment(boost::interprocess::open_read_only, |
| 336 | sharedMemoryIdentifier.c_str()); |
| 337 | machineId = segment.find<UID>("machineId").first; |
| 338 | if (!machineId) |
| 339 | criticalError(FDB_EXIT_ERROR, "SharedMemoryError", "Could not locate shared memory - 'machineId'"); |
| 340 | return *machineId; |
| 341 | } catch (boost::interprocess::interprocess_exception& ex) { |
| 342 | // Retry in case the shared memory was deleted in between the call to open_or_create and open_read_only |
| 343 | // Don't keep trying forever in case this is caused by some other problem |
| 344 | if (++numTries == 10) |
| 345 | criticalError(FDB_EXIT_ERROR, |
| 346 | "SharedMemoryError", |
| 347 | format("Could not open shared memory - %s", ex.what()).c_str()); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | #endif |
| 352 | } |
| 353 | |
| 354 | ACTOR void failAfter(Future<Void> trigger, ISimulator::ProcessInfo* m = g_simulator.getCurrentProcess()) { |
| 355 | wait(trigger); |
| 356 | if (enableFailures) { |
| 357 | printf("Killing machine: %s at %f\n", m->address.toString().c_str(), now()); |
| 358 | g_simulator.killProcess(m, ISimulator::KillInstantly); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | void failAfter(Future<Void> trigger, Endpoint e) { |
| 363 | if (g_network == &g_simulator) |
| 364 | failAfter(trigger, g_simulator.getProcess(e)); |
no test coverage detected