From bc2dbc3601b8281777a4ff9002645aaf9cbd6b62 Mon Sep 17 00:00:00 2001 From: Gavin Halliday Date: Thu, 28 Nov 2024 11:33:05 +0000 Subject: [PATCH] HPCC-33045 Add an option to check size consistency within the write sync margin Signed-off-by: Gavin Halliday --- dali/base/dadfs.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/dali/base/dadfs.cpp b/dali/base/dadfs.cpp index 005767ac263..25c85376af5 100644 --- a/dali/base/dadfs.cpp +++ b/dali/base/dadfs.cpp @@ -90,6 +90,32 @@ enum MDFSRequestKind MDFS_MAX }; + +//-------------------------------------------------------------------------------------------------------------------- + +static unsigned dadfsHookId = 0; +static bool expertVerifyWriteSyncSizes = false; + +//Add any code for caching global configuration here... +MODULE_INIT(INIT_PRIORITY_STANDARD) +{ + auto updateFunc = [&](const IPropertyTree *oldComponentConfiguration, const IPropertyTree *oldGlobalConfiguration) + { + Owned componentConfig = getComponentConfig(); + Owned globalConfig = getGlobalConfig(); + expertVerifyWriteSyncSizes = componentConfig->getPropBool("expert/@verifyWriteSyncSizes", globalConfig->getPropBool("expert/@verifyWriteSyncSizes", false)); + }; + dadfsHookId = installConfigUpdateHook(updateFunc, true); + return true; +} + +MODULE_EXIT() +{ + removeConfigUpdateHook(dadfsHookId); +} + +//-------------------------------------------------------------------------------------------------------------------- + // Mutex for physical operations (remove/rename) static CriticalSection physicalChange; @@ -3813,13 +3839,33 @@ protected: friend class CDistributedFilePart; if (unlikely(elapsedMs < marginMs)) { LOG(MCuserProgress, "Delaying access to %s on %s for %ums to ensure write sync", queryLogicalName(), name, (unsigned)(marginMs - elapsedMs)); + if (expertVerifyWriteSyncSizes) + checkSizeConsistency("Before write sync delay"); MilliSleep(marginMs - elapsedMs); + if (expertVerifyWriteSyncSizes) + checkSizeConsistency("After write sync delay"); now = 0; // re-evaluate now - unlikely to actually happen } } } } + void checkSizeConsistency(const char * when) + { + auto checkPartSize = [this,when](unsigned idx) -> void + { + IDistributedFilePart &part = queryPart(idx); + offset_t size = part.getDiskSize(false, false); + if (size != (offset_t)-1) + { + offset_t physicalSize = part.getDiskSize(true, true); + if (size != physicalSize) + OWARNLOG("%s: Part %d of file %s is inconsistent: logical size = %" I64F "d, physical size = %" I64F "d", when, idx, queryLogicalName(), size, physicalSize); + } + }; + asyncFor(numParts(), checkPartSize); + } + bool hasDirPerPart() const { return FileDescriptorFlags::none != (fileFlags & FileDescriptorFlags::dirperpart);