Merge a date range into an existing date log with conflict resolution
MergeDateLogHandle merges a source date range into a destination date log, with support for conflict resolution based on specified flags. This is a high-level wrapper that manages synchronization, file I/O, and recovery operations for date log merge operations.
This function enables consolidation of multiple date logs or date ranges into a single authoritative date log. It supports two merge strategies:
HRESULT _Must_inspect_result_ _Success_(SUCCEEDED(return)) MergeDateLogHandle(
_Inout_ _Pre_valid_ DATE_LOG_HANDLE hDestDateLog,
_In_ __readonly _Pre_valid_ DATE_RANGE_HANDLE hSourceDateLog,
_In_ DWORD dwFlags
);
Standard C calling convention with SAL annotations for parameter validation and return value inspection.
[In, Out] DATE_LOG_HANDLE
Handle to the destination date log that will be modified with merged data.
NewDateLogHandle()[In] DATE_RANGE_HANDLE
Read-only handle to the source date range to merge into the destination.
[In] DWORD
Flags controlling merge behavior and options. Exactly one conflict resolution flag is required:
| Flag | Value | Description |
|---|---|---|
| DATE_RANGE_MERGE_FAVOR_DEST | 0x04 | Keep destination GUIDs in overlapping date range. When the same dates exist in both logs, the destination's UUID is preserved. This is useful when the destination is the authoritative source. |
| DATE_RANGE_MERGE_FAVOR_SOURCE | 0x08 | Replace destination GUIDs with source values in overlapping range. When the same dates exist in both logs, the source's UUID is used. This is useful when the source has more recent or preferred data. |
| DATE_RANGE_MERGE_RESTORE_ON_FAILURE | 0x10 | (Optional) Enable automatic recovery if merge fails. Requires destination file info to be present. Creates backup of original array and file regions before modifying. On failure, restores original state. |
Merge operation completed successfully. Destination date log has been updated with merged data.
Either destination or source handle is invalid, not a date log/range, or context is NULL.
Flags parameter is invalid. Neither DATE_RANGE_MERGE_FAVOR_DEST nor DATE_RANGE_MERGE_FAVOR_SOURCE was specified.
Failed to acquire required mutex locks within 30-second timeout. Indicates another operation is holding locks or system is under resource contention.
Generic synchronization error from mutex or lock acquisition failure.
Failed to allocate memory for merge context or backup structures.
Merge lock context allocation failed or internal handle validation failed.
See return codes from MergeDateLogCores() including:
Array or file restoration failed after merge failure. Destination context may be invalid.
File region could not be restored from backup after failed merge.
// Recommended error checking pattern
HRESULT hr = MergeDateLogHandle(
hDestLog,
hSourceLog,
DATE_RANGE_MERGE_FAVOR_SOURCE | DATE_RANGE_MERGE_RESTORE_ON_FAILURE
);
if (SUCCEEDED(hr)) {
// Merge completed successfully
printf("Merge successful\n");
} else if (hr == ERR_DATE_LOG_PENDING_IO) {
// Retry operation after delay
printf("Merge in progress, retry later\n");
} else {
// Log error and handle gracefully
printf("Merge failed: 0x%08X\n", hr);
}
The function uses consistent lock ordering to prevent deadlocks:
Once all locks are acquired:
MERGE_LOCK_CONTEXT for tracking merge stateMergeDateLogCores() to perform in-memory mergebHasChanged = TRUEMergeDateLogFileInfo()If destination has associated file info (pDateRangeDest->pFileInfo is not NULL):
If DATE_RANGE_MERGE_RESTORE_ON_FAILURE flag is set and merge/file update fails:
In the __finally block: