Append one slot index to the roster file. Uses a persistent open write fd to avoid per-call open/close overhead. Records the byte offset of the new entry in ``_roster_slot_offsets`` so that ``_roster_remove`` can tombstone it in O(1) without re-reading.
(self, slot)
| 506 | return self._roster_wfd |
| 507 | |
| 508 | def _roster_append(self, slot): |
| 509 | """ |
| 510 | Append one slot index to the roster file. |
| 511 | |
| 512 | Uses a persistent open write fd to avoid per-call open/close overhead. |
| 513 | Records the byte offset of the new entry in ``_roster_slot_offsets`` |
| 514 | so that ``_roster_remove`` can tombstone it in O(1) without re-reading. |
| 515 | """ |
| 516 | wfd = self._roster_wfd_open() |
| 517 | if wfd is None: |
| 518 | return |
| 519 | try: |
| 520 | byte_offset = wfd.seek(0, 2) # seek to end to get current size |
| 521 | wfd.write(struct.pack(_ROSTER_ENTRY_FMT, slot)) |
| 522 | wfd.flush() |
| 523 | _fsync_fd_maybe(wfd.fileno()) |
| 524 | self._roster_slot_offsets[slot] = byte_offset |
| 525 | except OSError as exc: |
| 526 | log.error("Error appending to roster %s: %s", self.roster_path, exc) |
| 527 | try: |
| 528 | wfd.close() |
| 529 | except OSError: |
| 530 | pass |
| 531 | self._roster_wfd = None |
| 532 | self._roster_invalidate() |
| 533 | |
| 534 | def _roster_remove(self, slot): |
| 535 | """ |
no test coverage detected