Skip to content

Commit

Permalink
pool: simplify inotify support in pool.
Browse files Browse the repository at this point in the history
Motivation:

The pool will suppress sending read or write events if they are
happening too often.  This is injected as a setter; however, the value
isn't adjusted after a file is opened.

Modification:

Mark field-members 'final' and inject value with the constructor.

Result:

No user- or admin obserable changes.  Less code, so may be easier to
maintain.

Target: master
Requires-notes: no
Requires-book: no
Patch: https://rb.dcache.org/r/13056/
Acked-by: Lea Morschel
  • Loading branch information
paulmillar committed Jun 29, 2021
1 parent 9a2c99a commit 0067f72
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,20 @@ private enum Operation {
private final PnfsId target;
private final boolean isOpenForRead;
private final NotificationAmplifier notification;
private final Duration suppressDuration;

private Operation lastOperation;
private Instant whenSendNextEvent;
private Duration suppressDuration = Duration.ZERO;


public InotifyChannel(RepositoryChannel inner, NotificationAmplifier notification,
PnfsId target, boolean openForWrite)
PnfsId target, boolean openForWrite, Duration suppressDuration)
{
this.inner = inner;
this.target = target;
isOpenForRead = !openForWrite;
this.notification = notification;
}

public synchronized void setSuppressDuration(Duration duration)
{
Instant newWhenSendNextEvent = whenSendNextEvent == null
? null
: whenSendNextEvent.minus(suppressDuration).plus(duration);

suppressDuration = duration;
whenSendNextEvent = newWhenSendNextEvent;
this.suppressDuration = suppressDuration;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class InotifyReplicaRecord extends ForwardingReplicaRecord
{
private final ReplicaRecord inner;
private final NotificationAmplifier notification;

private Duration suppressDuration = Duration.ZERO;
private final Duration suppressDuration;

public enum OpenFlags implements OpenOption
{
Expand All @@ -58,19 +57,11 @@ public enum OpenFlags implements OpenOption


public InotifyReplicaRecord(ReplicaRecord inner, NotificationAmplifier notification,
PnfsId target)
PnfsId target, Duration suppressDuration)
{
this.inner = inner;
this.notification = notification;
}

/**
* Update the suppression period for all subsequently opened
* RepositoryChannel. Any already opened channels are not affected.
*/
public void setSuppressDuration(Duration duration)
{
suppressDuration = duration;
this.suppressDuration = suppressDuration;
}

@Override
Expand All @@ -96,8 +87,7 @@ public RepositoryChannel openChannel(Set<? extends OpenOption> mode)
boolean openForWrite = mode.contains(StandardOpenOption.WRITE);

InotifyChannel channel = new InotifyChannel(innerChannel, notification,
getPnfsId(), openForWrite);
channel.setSuppressDuration(suppressDuration);
getPnfsId(), openForWrite, suppressDuration);
channel.sendOpenEvent();
return channel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public ReplicaRecord create(PnfsId id, Set<? extends OpenOption> flags)
throws DuplicateEntryException, CacheException
{
ReplicaRecord innerRecord = super.create(id, flags);
InotifyReplicaRecord record = new InotifyReplicaRecord(innerRecord, notification, id);
record.setSuppressDuration(suppression);
return record;
return new InotifyReplicaRecord(innerRecord, notification, id, suppression);
}

@Override
Expand All @@ -76,8 +74,6 @@ public ReplicaRecord get(PnfsId id) throws CacheException
return null;
}

InotifyReplicaRecord record = new InotifyReplicaRecord(innerRecord, notification, id);
record.setSuppressDuration(suppression);
return record;
return new InotifyReplicaRecord(innerRecord, notification, id, suppression);
}
}

0 comments on commit 0067f72

Please sign in to comment.