Skip to content

Commit

Permalink
poolmanager: Clarify use of preallocated space in pool selection
Browse files Browse the repository at this point in the history
Pool manager can make use of the fie size or preallocated space
during write pool selection. The field is unused for all other
pool selections, yet the field is present in the base class. This
makes the purpose of the field less clear than it should be.

This patch moves the field to the write pool selection message
and the field is changed to precallocated to reflect its use. It
differs from the file size in storage info/file attributes by
being a preallocation, not an exact size of the final file. It is
only ever used when locating a pool with enough free space.

Some DCAP specific code is moved from pool manager to the DCAP
door.

The patch also makes file size and checksum attributes required
for read pool selection. These should be available to a pool
when staging a file or copying it between pools.

Target: trunk
Require-book: no
Require-notes: no
Acked-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
Patch: http://rb.dcache.org/r/5322
  • Loading branch information
gbehrmann committed Apr 2, 2013
1 parent d180e90 commit f31e94b
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 163 deletions.
Expand Up @@ -2141,7 +2141,16 @@ public void fileAttributesAvailable()
//
// try to get some space to store the file.
//
getPoolMessage = new PoolMgrSelectWritePoolMsg(_fileAttributes,_protocolInfo,0) ;
long preallocated = 0L;
String value = _fileAttributes.getStorageInfo().getKey("alloc-size");
if (value != null) {
try {
preallocated = Long.parseLong(value);
} catch (NumberFormatException e) {
// bad values are ignored
}
}
getPoolMessage = new PoolMgrSelectWritePoolMsg(_fileAttributes, _protocolInfo, preallocated);
getPoolMessage.setIoQueueName(_ioQueueName );
if( _path != null ) {
getPoolMessage.setPnfsPath(_path);
Expand Down Expand Up @@ -2181,7 +2190,6 @@ public void fileAttributesAvailable()
getPoolMessage =
new PoolMgrSelectReadPoolMsg(_fileAttributes,
_protocolInfo,
0,
_readPoolSelectionContext,
allowedStates);
getPoolMessage.setIoQueueName(_ioQueueName );
Expand Down
Expand Up @@ -1005,8 +1005,7 @@ private PnfsFlagReply setPnfsFlag(


PoolMgrReplicateFileMsg select =
new PoolMgrReplicateFileMsg(fileAttributesMsg.getFileAttributes(),
pinfo, 0L);
new PoolMgrReplicateFileMsg(fileAttributesMsg.getFileAttributes(), pinfo);

msg = new CellMessage( new CellPath("PoolManager"),select ) ;

Expand Down
Expand Up @@ -397,7 +397,7 @@ public synchronized void messageToForward(PoolMgrSelectPoolMsg msg)

int diff = 1;
long pinned =
(msg instanceof PoolMgrSelectWritePoolMsg) ? msg.getFileSize() : 0;
(msg instanceof PoolMgrSelectWritePoolMsg) ? ((PoolMgrSelectWritePoolMsg) msg).getPreallocated() : 0;
queue.modifyQueue(diff);
spaceInfo.modifyPinnedSpace(pinned);
considerInvalidatingCache(currentPerformanceCost, costInfo);
Expand Down
66 changes: 11 additions & 55 deletions modules/dcache/src/main/java/diskCacheV111/poolManager/PoolManagerV5.java 100755 → 100644
Expand Up @@ -483,11 +483,9 @@ public String apply(PoolSelectionUnit.SelectionPool pool) {
throw new CacheException(57, "No appropriate pools found for link: " + linkName);
}

FileAttributes fileAttributes = new FileAttributes();
fileAttributes.setSize(filesize);
Partition partition =
_poolMonitor.getPartitionManager().getPartition(link.getTag());
msg.setPoolName(partition.selectWritePool(_costModule, pools, fileAttributes).getName());
msg.setPoolName(partition.selectWritePool(_costModule, pools, new FileAttributes(), filesize).getName());
msg.setSucceeded();
return msg;
}
Expand Down Expand Up @@ -673,8 +671,8 @@ public void setFileSize( long fileSize ){}
}
*/

private boolean quotasExceeded( StorageInfo info ){

private boolean quotasExceeded(FileAttributes fileAttributes) {
StorageInfo info = fileAttributes.getStorageInfo();
String storageClass = info.getStorageClass()+"@"+info.getHsm() ;

QuotaMgrCheckQuotaMessage quotas = new QuotaMgrCheckQuotaMessage( storageClass ) ;
Expand Down Expand Up @@ -702,28 +700,6 @@ private boolean quotasExceeded( StorageInfo info ){

}

private long determineExpectedFileSize(long expectedLength, StorageInfo storageInfo)
{
if (expectedLength > 0) {
return expectedLength;
}

if (storageInfo.getFileSize() > 0) {
return storageInfo.getFileSize();
}

String s = storageInfo.getKey("alloc-size");
if (s != null) {
try {
return Long.parseLong(s);
} catch (NumberFormatException e) {
// bad values are ignored
}
}

return 0;
}

public DelayedReply messageArrived(PoolManagerSelectLinkGroupForWriteMessage message)
{
if (message.getStorageInfo() == null) {
Expand Down Expand Up @@ -852,43 +828,23 @@ public WriteRequestHandler(CellMessage envelope,

@Override
public void run(){
FileAttributes fileAttributes = _request.getFileAttributes();
StorageInfo storageInfo = fileAttributes.getStorageInfo();
ProtocolInfo protocolInfo = _request.getProtocolInfo();

StorageInfo storageInfo = _request.getStorageInfo() ;
ProtocolInfo protocolInfo = _request.getProtocolInfo() ;

_log.info( _pnfsId.toString()+" write handler started" );
_log.info("{} write handler started", _pnfsId);
long started = System.currentTimeMillis();

if( storageInfo == null ){
requestFailed( 21 , "Storage info not available for write request : "+_pnfsId ) ;
return ;
}else if( protocolInfo == null ){
requestFailed( 22 , "Protocol info not available for write request : "+_pnfsId ) ;
return ;
}
if( _quotasEnabled && quotasExceeded( storageInfo ) ){
if( _quotasEnabled && quotasExceeded(fileAttributes) ){
requestFailed( 55 , "Quotas Exceeded for StorageClass : "+storageInfo.getStorageClass() ) ;
return ;
}

long expectedLength =
determineExpectedFileSize(_request.getFileSize(), storageInfo);

/* The cost module relies on the expected file size.
*/
_request.setFileSize(expectedLength);

try{

FileAttributes fileAttributes = new FileAttributes();
fileAttributes.setPnfsId(_pnfsId);
fileAttributes.setStorageInfo(storageInfo);
fileAttributes.setSize(expectedLength);
try {
PoolInfo pool =
_poolMonitor
.getPoolSelector(fileAttributes, protocolInfo, _request
.getLinkGroup())
.selectWritePool();
.getPoolSelector(fileAttributes, protocolInfo, _request.getLinkGroup())
.selectWritePool(_request.getPreallocated());

_log.info("{} write handler selected {} after {} ms", _pnfsId, pool.getName(),
System.currentTimeMillis() - started);
Expand Down
Expand Up @@ -172,7 +172,7 @@ public List<List<PoolInfo>> getReadPools()
}

@Override
public PoolInfo selectWritePool()
public PoolInfo selectWritePool(long preallocated)
throws CacheException
{
PoolPreferenceLevel[] levels = match(DirectionType.WRITE);
Expand All @@ -191,7 +191,7 @@ public PoolInfo selectWritePool()
if (!pools.isEmpty()) {
Partition partition =
_partitionManager.getPartition(level.getTag());
return partition.selectWritePool(_costModule, pools, _fileAttributes);
return partition.selectWritePool(_costModule, pools, _fileAttributes, preallocated);
}
}

Expand Down
Expand Up @@ -673,8 +673,7 @@ public void messageArrived(CellMessage envelope,
new PoolMgrReplicateFileMsg(fileAttributes,
new DCapProtocolInfo("DCap", 3, 0,
new InetSocketAddress(args.argv(1),
2222)),
fileAttributes.getStorageInfo().getFileSize());
2222)));

sendMessage( new CellMessage(new CellPath("PoolManager"), req) );

Expand Down
Expand Up @@ -333,6 +333,9 @@ public void createEntryResponseArrived(PnfsCreateEntryMessage create)
manager.persist(this);

fileAttributes = create.getFileAttributes();
if (size != null) {
fileAttributes.setSize(size);
}
pnfsId = create.getPnfsId();
pnfsIdString = pnfsId.toString();
info.setPnfsId(pnfsId);
Expand All @@ -349,7 +352,7 @@ public void storageInfoArrived(PnfsGetStorageInfoMessage storage_info_msg)
return;
}
if(!store && tlog != null) {
tlog.middle(storage_info_msg.getStorageInfo().getFileSize());
tlog.middle(storage_info_msg.getFileAttributes().getSize());
}
//
// Added by litvinse@fnal.gov
Expand Down Expand Up @@ -385,18 +388,9 @@ public void storageInfoArrived(PnfsGetStorageInfoMessage storage_info_msg)
public void selectPool()
{
protocol_info = manager.getProtocolInfo(transferRequest);
long sizeToSend =transferRequest.getSize() == null ? 0L: transferRequest
.getSize();
PoolMgrSelectPoolMsg request =
store ?
new PoolMgrSelectWritePoolMsg(fileAttributes,
protocol_info,
sizeToSend)
:
new PoolMgrSelectReadPoolMsg(fileAttributes,
protocol_info,
sizeToSend,
_readPoolSelectionContext);
PoolMgrSelectPoolMsg request = store
? new PoolMgrSelectWritePoolMsg(fileAttributes, protocol_info, (size == null) ? 0L: size)
: new PoolMgrSelectReadPoolMsg(fileAttributes, protocol_info, _readPoolSelectionContext);
request.setPnfsPath(pnfsPath);
request.setSubject(transferRequest.getSubject());
log.debug("PoolMgrSelectPoolMsg: " + request );
Expand Down
Expand Up @@ -4820,6 +4820,7 @@ public void selectPool(CellMessage cellMessage,
}
return;
}
PoolMgrSelectWritePoolMsg selectWritePool = (PoolMgrSelectWritePoolMsg) selectPool;
File file = null;
try {
logger.debug("selectPool: getFiles({})", pnfsPath);
Expand All @@ -4835,15 +4836,15 @@ public void selectPool(CellMessage cellMessage,
logger.info("failed to find pool: {}", e.getMessage());
}
if(file==null) {
StorageInfo storageInfo = selectPool.getStorageInfo();
StorageInfo storageInfo = selectWritePool.getStorageInfo();
AccessLatency al;
RetentionPolicy rp;
String defaultSpaceToken;
al = storageInfo.getAccessLatency();
rp = storageInfo.getRetentionPolicy();
defaultSpaceToken=storageInfo.getMap().get("writeToken");
ProtocolInfo protocolInfo = selectPool.getProtocolInfo();
Subject subject = selectPool.getSubject();
ProtocolInfo protocolInfo = selectWritePool.getProtocolInfo();
Subject subject = selectWritePool.getSubject();
AuthorizationRecord authRecord;
if (Subjects.getFqans(subject).isEmpty()&&
Subjects.getUserName(subject)==null) {
Expand All @@ -4860,8 +4861,8 @@ public void selectPool(CellMessage cellMessage,
"calling reserveAndUseSpace()");

file = reserveAndUseSpace(pnfsPath,
null, // selectPool.getPnfsId(),
selectPool.getFileSize(),
null, // selectWritePool.getPnfsId(),
selectWritePool.getPreallocated(),
al,
rp,
authRecord,
Expand Down Expand Up @@ -4900,21 +4901,21 @@ public void selectPool(CellMessage cellMessage,
long fileId = useSpace(spaceToken,
voGroup,
voRole,
selectPool.getFileSize(),
selectWritePool.getPreallocated(),
lifetime,
pnfsPath,
selectPool.getPnfsId());
selectWritePool.getPnfsId());
file = getFile(fileId);
}
}
else {
if (isReply&&selectPool.getReturnCode()==0) {
if (isReply&&selectWritePool.getReturnCode()==0) {
logger.debug("selectPool: file is not null, " +
"calling updateSpaceFile()");
updateSpaceFile(file.getId(),null,null,pnfsId,null,null,null);
}
}
if (isReply&&selectPool.getReturnCode()!=0) {
if (isReply&&selectWritePool.getReturnCode()!=0) {
Connection connection = null;
try {
connection = connection_pool.getConnection();
Expand Down Expand Up @@ -4948,8 +4949,8 @@ public void selectPool(CellMessage cellMessage,
long linkGroupid = space.getLinkGroupId();
LinkGroup linkGroup = getLinkGroup(linkGroupid);
String linkGroupName = linkGroup.getName();
selectPool.setLinkGroup(linkGroupName);
StorageInfo storageInfo = selectPool.getStorageInfo();
selectWritePool.setLinkGroup(linkGroupName);
StorageInfo storageInfo = selectWritePool.getStorageInfo();
storageInfo.setKey("SpaceToken",Long.toString(spaceId));
if (storageInfo.getFileSize() == 0 &&
file.getSizeInBytes() > 1) {
Expand Down
Expand Up @@ -216,7 +216,6 @@ public BringOnlineState() {
PoolMgrSelectReadPoolMsg msg =
new PoolMgrSelectReadPoolMsg(_attributes,
getProtocolInfo(),
_attributes.getSize(),
_selectPoolContext);
msg.setSkipCostUpdate(true);
msg.setSubject(_subject);
Expand Down
Expand Up @@ -20,9 +20,9 @@ public class PoolMgrReplicateFileMsg extends PoolMgrSelectReadPoolMsg {
private int _destinationFileStatus = Pool2PoolTransferMsg.UNDETERMINED ;

/** Creates a new instance of PoolMgrReplicateFile */
public PoolMgrReplicateFileMsg(FileAttributes fileAttributes, ProtocolInfo protocolInfo, long fileSize)
public PoolMgrReplicateFileMsg(FileAttributes fileAttributes, ProtocolInfo protocolInfo)
{
super(fileAttributes, protocolInfo, fileSize, null);
super(fileAttributes, protocolInfo, null);
}
public void setAllowRestore( boolean allowRestore ){
_allowRestore = allowRestore ;
Expand Down
Expand Up @@ -13,7 +13,6 @@ public class PoolMgrSelectPoolMsg extends PoolMgrGetPoolMsg {
private static final long serialVersionUID = -5874326080375390208L;

private ProtocolInfo _protocolInfo;
private long _fileSize;
private String _ioQueueName;
private String _pnfsPath;
private String _linkGroup;
Expand All @@ -22,20 +21,17 @@ public class PoolMgrSelectPoolMsg extends PoolMgrGetPoolMsg {
private boolean _skipCostUpdate;

public PoolMgrSelectPoolMsg(FileAttributes fileAttributes,
ProtocolInfo protocolInfo,
long fileSize)
ProtocolInfo protocolInfo)
{
this(fileAttributes, protocolInfo, fileSize, RequestContainerV5.allStates);
this(fileAttributes, protocolInfo, RequestContainerV5.allStates);
}

public PoolMgrSelectPoolMsg(FileAttributes fileAttributes,
ProtocolInfo protocolInfo,
long fileSize,
EnumSet<RequestContainerV5.RequestState> allowedStates)
{
super(fileAttributes);
_protocolInfo = protocolInfo;
_fileSize = fileSize;
_allowedStates = allowedStates;
}

Expand All @@ -49,13 +45,6 @@ public boolean getSkipCostUpdate()
return _skipCostUpdate;
}

public void setFileSize(long fileSize)
{
_fileSize = fileSize;
}

public long getFileSize(){ return _fileSize; }

public ProtocolInfo getProtocolInfo(){ return _protocolInfo; }
public void setProtocolInfo( ProtocolInfo protocolInfo ){ _protocolInfo = protocolInfo ; }
public void setIoQueueName( String ioQueueName ){ _ioQueueName = ioQueueName ; }
Expand Down
Expand Up @@ -53,34 +53,31 @@ public class PoolMgrSelectReadPoolMsg extends PoolMgrSelectPoolMsg

public PoolMgrSelectReadPoolMsg(FileAttributes fileAttributes,
ProtocolInfo protocolInfo,
long fileSize,
Context context)
{
this(fileAttributes, protocolInfo, fileSize, context,
RequestContainerV5.allStates);
this(fileAttributes, protocolInfo, context, RequestContainerV5.allStates);
checkArgument(fileAttributes.getDefinedAttributes().containsAll(getRequiredAttributes()),
"Required attributes are missing"); }
"Required attributes are missing");
}

/**
* @param fileAttributes FileAttributes of the file to read
* @param protocolInfo ProtocolInfo describe the transfer
* @param fileSize The size of the file
* @param context The context of the previous attempt; may be null
* @param allowedStates Allowed states of the pool manager state machine
*/
public PoolMgrSelectReadPoolMsg(FileAttributes fileAttributes,
ProtocolInfo protocolInfo,
long fileSize,
Context context,
EnumSet<RequestContainerV5.RequestState> allowedStates)
{
super(fileAttributes, protocolInfo , fileSize , allowedStates);
super(fileAttributes, protocolInfo, allowedStates);
_context = (context == null) ? new Context() : context;
}

public static EnumSet<FileAttribute> getRequiredAttributes()
{
return EnumSet.of(PNFSID, STORAGEINFO, LOCATIONS);
return EnumSet.of(PNFSID, STORAGEINFO, LOCATIONS, SIZE);
}

public Context getContext()
Expand Down

0 comments on commit f31e94b

Please sign in to comment.