diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 0f304f42b7a741..4ad9294c5afcea 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -939,6 +939,7 @@ - (void)_handleEventReport:(NSArray *> *)eventRepor } } } + MTR_LOG_INFO("%@ _getCachedDataVersions dataVersions count: %lu readCache count: %lu", self, dataVersions.count, _readCache.count); os_unfair_lock_unlock(&self->_lock); return dataVersions; @@ -1983,6 +1984,7 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray *)attributeValues reportChanges:(BOOL)reportChanges { + MTR_LOG_INFO("%@ setAttributeValues count: %lu reportChanges: %d", self, attributeValues.count, reportChanges); os_unfair_lock_lock(&self->_lock); if (reportChanges) { diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index edd521845b2415..8b7c1a3a231a2f 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -887,7 +887,8 @@ - (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID // Load persisted attributes if they exist. NSArray * attributesFromCache = [_controllerDataStore getStoredAttributesForNodeID:nodeID]; - if (attributesFromCache) { + MTR_LOG_INFO("Loaded %lu attributes from storage for %@", attributesFromCache.count, deviceToReturn); + if (attributesFromCache.count) { [deviceToReturn setAttributeValues:attributesFromCache reportChanges:NO]; } } diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm index 876af930807a5b..0495211b76b449 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm @@ -503,6 +503,7 @@ - (void)_pruneEmptyStoredAttributesBranches NSMutableArray * nodeIndex = [self _fetchNodeIndex].mutableCopy; NSUInteger nodeIndexCount = nodeIndex.count; + NSUInteger storeFailures = 0; for (NSNumber * nodeID in nodeIndex) { // Fetch endpoint index NSMutableArray * endpointIndex = [self _fetchEndpointIndexForNodeID:nodeID].mutableCopy; @@ -529,35 +530,55 @@ - (void)_pruneEmptyStoredAttributesBranches if (!attributeIndex.count) { [clusterIndex removeObject:clusterID]; } else if (attributeIndex.count != attributeIndexCount) { - [self _storeAttributeIndex:attributeIndex forNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + BOOL success = [self _storeAttributeIndex:attributeIndex forNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + if (!success) { + storeFailures++; + MTR_LOG_INFO("Store failed for attributeIndex"); + } } } if (!clusterIndex.count) { [endpointIndex removeObject:endpointID]; } else if (clusterIndex.count != clusterIndexCount) { - [self _storeClusterIndex:clusterIndex forNodeID:nodeID endpointID:endpointID]; + BOOL success = [self _storeClusterIndex:clusterIndex forNodeID:nodeID endpointID:endpointID]; + if (!success) { + storeFailures++; + MTR_LOG_INFO("Store failed for clusterIndex"); + } } } if (!endpointIndex.count) { [nodeIndex removeObject:nodeID]; } else if (endpointIndex.count != endpointIndexCount) { - [self _storeEndpointIndex:endpointIndex forNodeID:nodeID]; + BOOL success = [self _storeEndpointIndex:endpointIndex forNodeID:nodeID]; + if (!success) { + storeFailures++; + MTR_LOG_INFO("Store failed for endpointIndex"); + } } } if (!nodeIndex.count) { [self _deleteNodeIndex]; } else if (nodeIndex.count != nodeIndexCount) { - [self _storeNodeIndex:nodeIndex]; + BOOL success = [self _storeNodeIndex:nodeIndex]; + if (!success) { + storeFailures++; + MTR_LOG_INFO("Store failed for nodeIndex"); + } + } + + if (storeFailures) { + MTR_LOG_ERROR("Store failed in _pruneEmptyStoredAttributesBranches: %lu", (unsigned long) storeFailures); } } - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NSNumber *)nodeID { dispatch_async(_storageDelegateQueue, ^{ - BOOL anyStoreFailed = NO; + NSUInteger storeFailures = 0; for (NSDictionary * dataValue in dataValues) { MTRAttributePath * path = dataValue[MTRAttributePathKey]; @@ -573,7 +594,8 @@ - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NS storeFailed = ![self _storeNodeIndex:[nodeIndex arrayByAddingObject:nodeID]]; } if (storeFailed) { - anyStoreFailed = YES; + storeFailures++; + MTR_LOG_INFO("Store failed for nodeIndex"); continue; } @@ -586,7 +608,8 @@ - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NS storeFailed = ![self _storeEndpointIndex:[endpointIndex arrayByAddingObject:path.endpoint] forNodeID:nodeID]; } if (storeFailed) { - anyStoreFailed = YES; + storeFailures++; + MTR_LOG_INFO("Store failed for endpointIndex"); continue; } @@ -599,7 +622,8 @@ - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NS storeFailed = ![self _storeClusterIndex:[clusterIndex arrayByAddingObject:path.cluster] forNodeID:nodeID endpointID:path.endpoint]; } if (storeFailed) { - anyStoreFailed = YES; + storeFailures++; + MTR_LOG_INFO("Store failed for clusterIndex"); continue; } @@ -615,20 +639,23 @@ - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NS storeFailed = ![self _storeAttributeIndex:[attributeIndex arrayByAddingObject:path.attribute] forNodeID:nodeID endpointID:path.endpoint clusterID:path.cluster]; } if (storeFailed) { - anyStoreFailed = YES; + storeFailures++; + MTR_LOG_INFO("Store failed for attributeIndex"); continue; } // Store value storeFailed = [self _storeAttributeValue:value forNodeID:nodeID endpointID:path.endpoint clusterID:path.cluster attributeID:path.attribute]; if (storeFailed) { - anyStoreFailed = YES; + storeFailures++; + MTR_LOG_INFO("Store failed for attribute value"); } } // In the rare event that store fails, allow all attribute store attempts to go through and prune empty branches at the end altogether. - if (anyStoreFailed) { + if (storeFailures) { [self _pruneEmptyStoredAttributesBranches]; + MTR_LOG_ERROR("Store failed in -storeAttributeValues:forNodeID: %lu", (unsigned long) storeFailures); } }); } diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerLocalTestStorage.m b/src/darwin/Framework/CHIP/MTRDeviceControllerLocalTestStorage.mm similarity index 69% rename from src/darwin/Framework/CHIP/MTRDeviceControllerLocalTestStorage.m rename to src/darwin/Framework/CHIP/MTRDeviceControllerLocalTestStorage.mm index 4d52e4bf18afb6..7e3eff8e368567 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerLocalTestStorage.m +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerLocalTestStorage.mm @@ -16,6 +16,7 @@ */ #import "MTRDeviceControllerLocalTestStorage.h" +#import "MTRLogging_Internal.h" #if MTR_PER_CONTROLLER_STORAGE_ENABLED @@ -36,12 +37,18 @@ + (void)setLocalTestStorageEnabled:(BOOL)localTestStorageEnabled { NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:kLocalTestUserDefaultDomain]; [defaults setBool:localTestStorageEnabled forKey:kLocalTestUserDefaultEnabledKey]; + MTR_LOG_INFO("MTRDeviceControllerLocalTestStorage setLocalTestStorageEnabled %d", localTestStorageEnabled); + BOOL storedLocalTestStorageEnabled = [defaults boolForKey:kLocalTestUserDefaultEnabledKey]; + if (storedLocalTestStorageEnabled != localTestStorageEnabled) { + MTR_LOG_ERROR("MTRDeviceControllerLocalTestStorage setLocalTestStorageEnabled %d failed", localTestStorageEnabled); + } } - (instancetype)initWithPassThroughStorage:(id)passThroughStorage { if (self = [super init]) { _passThroughStorage = passThroughStorage; + MTR_LOG_INFO("MTRDeviceControllerLocalTestStorage initialized with pass-through storage %@", passThroughStorage); } return self; } @@ -58,7 +65,12 @@ - (instancetype)initWithPassThroughStorage:(id