Skip to content

Commit

Permalink
info/space-manager: monitor number of files in reservation
Browse files Browse the repository at this point in the history
Motivation:

WLCG now wants to know how many files are stored in a space reservation.

Modification:

Update space manager to support an updated message that queries space
metadata and optionally also the number of files stored in each
reservation.

Update info to present this information in serialised output.

Result:

info clients (such as info-provider and storage-report) are now informed
of the number of files stored in a space reservation.

Target: master
Request: 4.2
Request: 4.1
Require-notes: yes
Require-book: no
  • Loading branch information
paulmillar committed Oct 10, 2018
1 parent 2dbac4d commit 9a5efb7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
Expand Up @@ -5,6 +5,7 @@

import java.util.Collection;
import java.util.Date;
import java.util.OptionalLong;

import diskCacheV111.services.space.Space;
import diskCacheV111.services.space.message.GetSpaceTokensMessage;
Expand Down Expand Up @@ -84,6 +85,15 @@ public boolean handleMessage(Message messagePayload, long metricLifetime)
addLinkgroup(update, thisSpacePath, String.valueOf(space.getLinkGroupId()), String.valueOf(space.getId()), metricLifetime);

addVoInfo(update, thisSpacePath.newChild("authorisation"), space.getVoGroup(), space.getVoRole(), metricLifetime);

OptionalLong fileCount = space.getNumberofFiles();
StatePath fileCountPath = thisSpacePath.newChild("file-count");
if (fileCount.isPresent()) {
update.appendUpdate(fileCountPath,
new IntegerStateValue(fileCount.getAsLong(), metricLifetime));
} else {
update.purgeUnder(fileCountPath);
}
}

_sum.enqueueUpdate(update);
Expand Down
Expand Up @@ -56,7 +56,7 @@ public void trigger()

LOGGER.trace("Sending space token details request message");

_sender.sendMessage(_metricLifetime, _spacemanager, new GetSpaceTokensMessage());
_sender.sendMessage(_metricLifetime, _spacemanager, new GetSpaceTokensMessage(true));
}

@Override
Expand Down
Expand Up @@ -367,7 +367,36 @@ private void expireSpaceReservations() throws DataAccessException

private void getValidSpaceTokens(GetSpaceTokensMessage msg) throws DataAccessException
{
msg.setSpaceTokenSet(db.get(db.spaces().thatNeverExpire().whereStateIsIn(SpaceState.RESERVED), null));
List<Space> spaces = db.get(db.spaces().thatNeverExpire().whereStateIsIn(SpaceState.RESERVED), null);
if (msg.isFileCountRequested()) {
/*
* REVISIT: the database schema would support a query like:
*
* SELECT spacereservationid,description,COUNT(*)
* FROM srmspacefile f JOIN srmspace s ON s.id = f.spacereservationid
* GROUP BY spacereservationid, description;
*
* This has the advantage of being faster than querying each
* reservation individually: a test on DESY ATLAS instance, with
* four reservations with a combined total of 16,597,222 files,
* from 29,747,983 files in srmspacefile took ~5 seconds, whereas
* querying each file individually requires ~2.5 seconds per
* reservation.
*
* This approach is currently not possible, as it would require
* changes to the Space class.
*
* An alternative approach would be to update the database schema
* so that the number of files in a reservation is stored in
* srmspace and maintained by the stored procedure, similar to
* how other metrics are done currently.
*/
for (Space space : spaces) {
long fileCount = db.count(db.files().whereSpaceTokenIs(space.getId()).whereStateIsIn(FileState.STORED));
space.setNumberOfFiles(fileCount);
}
}
msg.setSpaceTokenSet(spaces);
}

private void getLinkGroups(GetLinkGroupsMessage msg) throws DataAccessException
Expand Down
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.Date;
import java.util.OptionalLong;

import diskCacheV111.util.AccessLatency;
import diskCacheV111.util.RetentionPolicy;
Expand All @@ -21,6 +22,7 @@ public class Space implements Serializable {
private Long expirationTime;
private String description;
private SpaceState state;
private Long numberOfFiles;

public Space(
long id,
Expand Down Expand Up @@ -120,6 +122,7 @@ public String toString() {
sb.append("state:").append(state).append(' ');
sb.append("used:").append(usedSizeInBytes).append(' ');
sb.append("allocated:").append(allocatedSpaceInBytes).append(' ');
sb.append("files:").append(numberOfFiles);
return sb.toString();
}

Expand Down Expand Up @@ -175,4 +178,14 @@ public void setExpirationTime(Long expirationTime)
{
this.expirationTime = expirationTime;
}

public void setNumberOfFiles(long count)
{
numberOfFiles = count;
}

public OptionalLong getNumberofFiles()
{
return numberOfFiles == null ? OptionalLong.empty() : OptionalLong.of(numberOfFiles);
}
}
Expand Up @@ -11,9 +11,17 @@ public class GetSpaceTokensMessage extends Message {
private static final long serialVersionUID = -419540669938740860L;

private Collection<Space> list = Collections.emptySet();
private final boolean isFileCountRequested;

public GetSpaceTokensMessage() {
setReplyRequired(true);
isFileCountRequested = false;
}

public GetSpaceTokensMessage(boolean isFileCountRequested)
{
setReplyRequired(true);
this.isFileCountRequested = isFileCountRequested;
}

public Collection<Space> getSpaceTokenSet() {
Expand All @@ -24,4 +32,7 @@ public void setSpaceTokenSet(Collection<Space> list) {
this.list = list;
}

public boolean isFileCountRequested() {
return isFileCountRequested;
}
}

0 comments on commit 9a5efb7

Please sign in to comment.