deleteExpiredKeys method

  1. @override
  2. @server
  3. @client
Future<bool> deleteExpiredKeys()
override

Removes all expired keys. Deletes are local-only — they are NOT appended to the commit log, so an expiry sweep never advances the local commitId and never propagates to other secondaries via sync. Expiry is treated as backend maintenance, not a sync-worthy mutation; clients drop expired keys independently using their own TTL bookkeeping.

Implementation

@override
@server
@client
Future<bool> deleteExpiredKeys() async {
  logger.finer('Removing expired keys');
  bool result = true;
  try {
    List<String> expiredKeys = await (await getExpiredKeys()).toList();
    if (expiredKeys.isEmpty) {
      return result;
    }

    for (String element in expiredKeys) {
      try {
        // delete entries for expired keys will not be added to the commitLog
        // Removal of expired keys will be handled on the client side
        await remove(element, skipCommit: true);
      } on KeyNotFoundException {
        continue;
      }
    }
    result = true;
  } on Exception catch (e) {
    result = false;
    logger.severe('Exception in deleteExpired keys: ${e.toString()}');
    throw DataStoreException(
        'exception in deleteExpiredKeys: ${e.toString()}');
  } on HiveError catch (error) {
    logger.severe('HiveAtKeyValueStore get error: $error');
    await _restartHiveBox(error);
    throw DataStoreException(error.message);
  }

  return result;
}