Commit 9e107ad9 authored by jan.koester's avatar jan.koester
Browse files

test

parent 1f8aa742
Loading
Loading
Loading
Loading
Loading
+30 −9
Original line number Diff line number Diff line
@@ -48,9 +48,12 @@

#ifdef _WIN32
#include <winsock2.h>
#include <io.h>
#include <fcntl.h>
#pragma comment(lib, "ws2_32.lib")
#else
#include <unistd.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -646,17 +649,35 @@ namespace authdb {
                    }
                }

                // Verify local store is writable
                // Verify local store is writable without polluting blocks.bin.
                // Previous approach wrote a sentinel record every health cycle
                // which accumulated thousands of dead records in the data file.
                bool store_ok = true;
                if (store_) {
                if (!cfg_.store_path.empty()) {
                    try {
                        // Write and remove a sentinel block to test I/O
                        const uint64_t sentinel_gid = 0;
                        const uint32_t sentinel_idx = UINT32_MAX;
                        uint8_t probe = 0x01;
                        store_ok = store_->store(sentinel_gid, sentinel_idx, &probe, 1);
                        if (store_ok)
                            store_->remove_group(sentinel_gid);
                        std::string probe_path = cfg_.store_path + "/.health_probe";
#ifdef _WIN32
                        int probe_fd = ::_open(probe_path.c_str(),
                                               _O_WRONLY | _O_CREAT | _O_TRUNC,
                                               _S_IREAD | _S_IWRITE);
                        if (probe_fd >= 0) {
                            store_ok = (::_write(probe_fd, "OK", 2) == 2);
                            ::_close(probe_fd);
                            ::_unlink(probe_path.c_str());
                        } else {
                            store_ok = false;
                        }
#else
                        int probe_fd = ::open(probe_path.c_str(),
                                              O_WRONLY | O_CREAT | O_TRUNC, 0644);
                        if (probe_fd >= 0) {
                            store_ok = (::write(probe_fd, "OK", 2) == 2);
                            ::close(probe_fd);
                            ::unlink(probe_path.c_str());
                        } else {
                            store_ok = false;
                        }
#endif
                    } catch (...) {
                        store_ok = false;
                    }