diff --git a/src/jrd/Mapping.cpp b/src/jrd/Mapping.cpp index e678ebbbb9..76b72379d0 100644 --- a/src/jrd/Mapping.cpp +++ b/src/jrd/Mapping.cpp @@ -676,18 +676,14 @@ public: sharedMemory->eventFini(&sMem->process[process].notifyEvent); sharedMemory->eventFini(&sMem->process[process].callbackEvent); - bool found = false; - - for (unsigned n = 0; n < sMem->processes; ++n) + while (sMem->processes) { - if (sMem->process[n].flags & MappingHeader::FLAG_ACTIVE) - { - found = true; + if (sMem->process[sMem->processes - 1].flags & MappingHeader::FLAG_ACTIVE) break; - } + sMem->processes--; } - if (!found) + if (!sMem->processes) sharedMemory->removeMapFile(); } @@ -753,15 +749,21 @@ public: (Arg::Gds(isc_map_event) << "POST").raise(); } + int tout = 0; while (sharedMemory->eventWait(¤t->callbackEvent, value, 10000) != FB_SUCCESS) { if (!ISC_check_process_existence(p->id)) { + MAP_DEBUG(fprintf(stderr, "clearMapping: dead process found %d", p->id)); + p->flags &= ~MappingHeader::FLAG_ACTIVE; sharedMemory->eventFini(&p->notifyEvent); sharedMemory->eventFini(&p->callbackEvent); break; } + + if (++tout >= 1000) // 10 sec + (Arg::Gds(isc_random) << "Timeout when waiting callback from other process.").raise(); } MAP_DEBUG(fprintf(stderr, "Notified pid %d about reset map %s\n", p->id, sMem->databaseForReset)); @@ -806,17 +808,34 @@ public: Guard gShared(tempSharedMemory); - for (process = 0; process < sMem->processes; ++process) + process = sMem->processes; + for (unsigned idx = 0; idx < sMem->processes; ++idx) { - if (!(sMem->process[process].flags & MappingHeader::FLAG_ACTIVE)) - break; + MappingHeader::Process& p = sMem->process[idx]; - if (!ISC_check_process_existence(sMem->process[process].id)) + if (p.id == processId) { - tempSharedMemory->eventFini(&sMem->process[process].notifyEvent); - tempSharedMemory->eventFini(&sMem->process[process].callbackEvent); + if (p.flags & MappingHeader::FLAG_ACTIVE) { + MAP_DEBUG(fprintf(stderr, "MappingIpc::setup: found existing entry for pid %d", processId)); + } - break; + process = idx; + continue; + } + + if ((p.flags & MappingHeader::FLAG_ACTIVE) && !ISC_check_process_existence(p.id)) + { + MAP_DEBUG(fprintf(stderr, "MappingIpc::setup: dead process found %d", p.id)); + + p.flags = 0; + tempSharedMemory->eventFini(&p.notifyEvent); + tempSharedMemory->eventFini(&p.callbackEvent); + } + + if (!(p.flags & MappingHeader::FLAG_ACTIVE)) + { + if (process == sMem->processes) + process = idx; } }