Skip to content

Commit

Permalink
Remove retries datastore from our Datastore service wrapper (#2954)
Browse files Browse the repository at this point in the history
See flutter/flutter#131310 for a detailed explanation of the problem this fix addresses. The main culprit was a change made to the Appengine dependency we use that added retries in the background.

*List which issues are fixed by this PR. You must list at least one issue.*
Fixes flutter/flutter#131192

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
  • Loading branch information
ricardoamador authored Jul 27, 2023
1 parent 4f8b761 commit 9dee587
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
59 changes: 24 additions & 35 deletions app_dart/lib/src/service/datastore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,63 +243,52 @@ class DatastoreService {
return shards;
}

// Note: please do not add retries to any of the following queries. The following
// change was made to add retries to the appengine grpc implementation of the
// datastore service: https://github.com/dart-lang/appengine/pull/167.
// Adding retries to the following queries will cause conflicts with commits
// and effectively prevent us from inserting update to Datastore.
//
// See this issue for a more detailed summary and analysis:
// https://github.com/flutter/flutter/issues/131310

/// Inserts [rows] into datastore sharding the inserts if needed.
Future<void> insert(List<Model<dynamic>> rows) async {
final List<List<Model<dynamic>>> shards = await shard(rows);
for (List<Model<dynamic>> shard in shards) {
await runTransactionWithRetries(
() async {
await db.withTransaction<void>((Transaction transaction) async {
transaction.queueMutations(inserts: shard);
await transaction.commit();
});
},
retryOptions: retryOptions,
);
await db.withTransaction<void>((Transaction transaction) async {
transaction.queueMutations(inserts: shard);
await transaction.commit();
});
}
}

/// Looks up registers by [keys].
Future<List<T?>> lookupByKey<T extends Model<dynamic>>(List<Key<dynamic>> keys) async {
List<T?> results = <T>[];
await runTransactionWithRetries(
() async {
await db.withTransaction<void>((Transaction transaction) async {
results = await transaction.lookup<T>(keys);
await transaction.commit();
});
},
retryOptions: retryOptions,
);
await db.withTransaction<void>((Transaction transaction) async {
results = await transaction.lookup<T>(keys);
await transaction.commit();
});
return results;
}

/// Looks up registers by value using a single [key].
Future<T> lookupByValue<T extends Model<dynamic>>(Key<dynamic> key, {T Function()? orElse}) async {
late T result;
await runTransactionWithRetries(
() async {
await db.withTransaction<void>((Transaction transaction) async {
result = await db.lookupValue<T>(key, orElse: orElse);
await transaction.commit();
});
},
retryOptions: retryOptions,
);
await db.withTransaction<void>((Transaction transaction) async {
result = await db.lookupValue<T>(key, orElse: orElse);
await transaction.commit();
});
return result;
}

/// Runs a function inside a transaction providing a [Transaction] parameter.
Future<T?> withTransaction<T>(Future<T> Function(Transaction) handler) async {
T? result;
await runTransactionWithRetries(
() async {
await db.withTransaction<void>((Transaction transaction) async {
result = await handler(transaction);
});
},
retryOptions: retryOptions,
);
await db.withTransaction<void>((Transaction transaction) async {
result = await handler(transaction);
});
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion dashboard/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ environment:
sdk: '>=2.18.0 <4.0.0'

dependencies:
collection: 1.17.2
collection: 1.18.0
fixnum: 1.1.0
flutter:
sdk: flutter
Expand Down

0 comments on commit 9dee587

Please sign in to comment.