ibessonov commented on code in PR #1226:
URL: https://github.com/apache/ignite-3/pull/1226#discussion_r1003027673
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/snapshot/outgoing/OutgoingSnapshotsManager.java:
##########
@@ -141,8 +183,50 @@ private CompletableFuture<Void> respond(
NetworkAddress sender,
Long correlationId
) {
- //TODO https://issues.apache.org/jira/browse/IGNITE-17262
+ //TODO https://issues.apache.org/jira/browse/IGNITE-17935
// Handle offline sender and stopped manager.
return messagingService.respond(sender, response, correlationId);
}
+
+ @Override
+ public PartitionSnapshots partitionSnapshots(PartitionKey partitionKey) {
+ return getPartitionSnapshots(partitionKey);
+ }
+
+ private static class PartitionSnapshotsImpl implements PartitionSnapshots {
+ private final List<OutgoingSnapshot> snapshots = new ArrayList<>();
+
+ private final List<OutgoingSnapshot> unmodifiableSnapshotsView =
unmodifiableList(snapshots);
+
+ private final ReadWriteLock lock = new ReentrantReadWriteLock();
+ private final ReusableLockLockup readLockLockup = new
ReusableLockLockup(lock.readLock());
+
+ private void addUnderLock(OutgoingSnapshot snapshot) {
+ lock.writeLock().lock();
+
+ try {
+ snapshots.add(snapshot);
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ private void removeUnderLock(OutgoingSnapshot snapshot) {
+ try {
+ snapshots.remove(snapshot);
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
+ @Override
+ public AutoLockup acquireReadLock() {
+ return readLockLockup.acquireLock();
+ }
+
+ @Override
+ public List<OutgoingSnapshot> ongoingSnapshots() {
+ return unmodifiableSnapshotsView;
+ }
Review Comment:
I know, but if we add enough of them, code overall becomes too bloated with
unnecessary things. You can create immutable wrapper in this method and not
store it as a field. Avoiding allocations in such places is the finest example
of preemptive optimizations that make code worse.
And let's be real, no one else will write to this collection. It just
doesn't happen in real code (like this one specifically)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]