MNT-20770: Share non responsive during direct download from S3 if content store selector is also configured

- add specific implementation for exists to bypass getting the complete reader and in some cases (e.g. aggregating a CachingContentStore) trigger a complete download of the file

cherry-picked from 933161a master to support/SP/7.N
This commit is contained in:
cturlica
2019-11-06 16:00:56 +02:00
parent ce2cb22342
commit 0f5f912a76

View File

@@ -23,8 +23,8 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.content.replication; package org.alfresco.repo.content.replication;
import java.util.List; import java.util.List;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReadWriteLock;
@@ -34,161 +34,232 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.AbstractContentStore; import org.alfresco.repo.content.AbstractContentStore;
import org.alfresco.repo.content.ContentContext; import org.alfresco.repo.content.ContentContext;
import org.alfresco.repo.content.ContentStore; import org.alfresco.repo.content.ContentStore;
import org.alfresco.repo.content.UnsupportedContentUrlException;
import org.alfresco.repo.content.caching.CachingContentStore; import org.alfresco.repo.content.caching.CachingContentStore;
import org.alfresco.service.cmr.repository.ContentIOException; import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.ContentWriter;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
* <h1><u>Aggregating Content Store</u></h1> * <h1><u>Aggregating Content Store</u></h1>
* <p> * <p>
* A content store implementation that aggregates a set of stores. Content is not * A content store implementation that aggregates a set of stores. Content is not
* persisted by this store, but rather it relies on any number of * persisted by this store, but rather it relies on any number of
* child {@link org.alfresco.repo.content.ContentStore stores} to provide access * child {@link org.alfresco.repo.content.ContentStore stores} to provide access
* to content readers and writers. * to content readers and writers.
* <p> * <p>
* The order in which the stores appear in the list of stores participating is * The order in which the stores appear in the list of stores participating is
* important. The first store in the list is known as the <i>primary store</i>. * important. The first store in the list is known as the <i>primary store</i>.
<p> <p>
* Content is written to the primary store only. The other stores are * Content is written to the primary store only. The other stores are
* only used to retrieve content and the primary store is not updated with * only used to retrieve content and the primary store is not updated with
* the content. * the content.
* *
* @author Derek Hulley * @author Derek Hulley
* @author Mark Rogers * @author Mark Rogers
* @see CachingContentStore * @see CachingContentStore
*/ */
public class AggregatingContentStore extends AbstractContentStore public class AggregatingContentStore extends AbstractContentStore
{ {
private static Log logger = LogFactory.getLog(AggregatingContentStore.class); private static Log logger = LogFactory.getLog(AggregatingContentStore.class);
private ContentStore primaryStore; private ContentStore primaryStore;
private List<ContentStore> secondaryStores; private List<ContentStore> secondaryStores;
private Lock readLock; private Lock readLock;
/** /**
* Default constructor * Default constructor
*/ */
public AggregatingContentStore() public AggregatingContentStore()
{ {
ReadWriteLock storeLock = new ReentrantReadWriteLock(); ReadWriteLock storeLock = new ReentrantReadWriteLock();
readLock = storeLock.readLock(); readLock = storeLock.readLock();
} }
/** /**
* Set the primary store that content will be replicated to or from * Set the primary store that content will be replicated to or from
* *
* @param primaryStore the primary content store * @param primaryStore the primary content store
*/ */
public void setPrimaryStore(ContentStore primaryStore) public void setPrimaryStore(ContentStore primaryStore)
{ {
this.primaryStore = primaryStore; this.primaryStore = primaryStore;
} }
/** /**
* Set the secondary stores that this component will replicate to or from * Set the secondary stores that this component will replicate to or from
* *
* @param secondaryStores a list of stores to replicate to or from * @param secondaryStores a list of stores to replicate to or from
*/ */
public void setSecondaryStores(List<ContentStore> secondaryStores) public void setSecondaryStores(List<ContentStore> secondaryStores)
{ {
this.secondaryStores = secondaryStores; this.secondaryStores = secondaryStores;
} }
/** /**
* @return Returns <tt>true</tt> if the primary store supports writing * @return Returns <tt>true</tt> if the primary store supports writing
*/ */
public boolean isWriteSupported() public boolean isWriteSupported()
{ {
return primaryStore.isWriteSupported(); return primaryStore.isWriteSupported();
} }
/** /**
* @return Returns <tt>true</tt> if the primary store supports the URL * @return Returns <tt>true</tt> if the primary store supports the URL
*/ */
@Override @Override
public boolean isContentUrlSupported(String contentUrl) public boolean isContentUrlSupported(String contentUrl)
{ {
return primaryStore.isContentUrlSupported(contentUrl); return primaryStore.isContentUrlSupported(contentUrl);
} }
/** /**
* @return Return the primary store root location * @return Return the primary store root location
*/ */
@Override @Override
public String getRootLocation() public String getRootLocation()
{ {
return primaryStore.getRootLocation(); return primaryStore.getRootLocation();
} }
/** /**
* Forwards the call directly to the first store in the list of stores. * Forwards the call directly to the first store in the list of stores.
*/ */
public ContentReader getReader(String contentUrl) throws ContentIOException public ContentReader getReader(String contentUrl) throws ContentIOException
{ {
if (primaryStore == null) if (primaryStore == null)
{ {
throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised"); throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
} }
// get a read lock so that we are sure that no replication is underway // get a read lock so that we are sure that no replication is underway
readLock.lock(); readLock.lock();
try try
{ {
// get a reader from the primary store // get a reader from the primary store
ContentReader primaryReader = primaryStore.getReader(contentUrl); ContentReader primaryReader = primaryStore.getReader(contentUrl);
// give it straight back if the content is there // give it straight back if the content is there
if (primaryReader.exists()) if (primaryReader.exists())
{ {
return primaryReader; return primaryReader;
} }
// the content is not in the primary reader so we have to go looking for it // the content is not in the primary reader so we have to go looking for it
for (ContentStore store : secondaryStores) for (ContentStore store : secondaryStores)
{ {
ContentReader reader = store.getReader(contentUrl); ContentReader reader = store.getReader(contentUrl);
if (reader.exists()) if (reader.exists())
{ {
// found the content in a secondary store // found the content in a secondary store
return reader; return reader;
} }
} }
return primaryReader; return primaryReader;
} }
finally finally
{ {
readLock.unlock(); readLock.unlock();
} }
} }
public ContentWriter getWriter(ContentContext ctx) public boolean exists(String contentUrl)
{ {
// get the writer if (primaryStore == null)
ContentWriter writer = primaryStore.getWriter(ctx); {
throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
return writer; }
}
// get a read lock so that we are sure that no replication is underway
/** readLock.lock();
* Performs a delete on the local store and if outbound replication is on, propogates try
* the delete to the other stores too. {
* // Keep track of the unsupported state of the content URL - it might be a rubbish URL
* @return Returns the value returned by the delete on the primary store. boolean contentUrlSupported = false;
*/
public boolean delete(String contentUrl) throws ContentIOException boolean contentUrlExists = false;
{
// delete on the primary store // Check the primary store
boolean deleted = primaryStore.delete(contentUrl); try
{
if (logger.isDebugEnabled()) contentUrlExists = primaryStore.exists(contentUrl);
{
logger.debug("Deleted content for URL: " + contentUrl); // At least the content URL was supported
} contentUrlSupported = true;
return deleted; }
} catch (UnsupportedContentUrlException e)
} {
// The store can't handle the content URL
}
if (contentUrlExists)
{
return true;
}
// the content is not in the primary store so we have to go looking for it
for (ContentStore store : secondaryStores)
{
contentUrlExists = false;
try
{
contentUrlExists = store.exists(contentUrl);
// At least the content URL was supported
contentUrlSupported = true;
}
catch (UnsupportedContentUrlException e)
{
// The store can't handle the content URL
}
if (contentUrlExists)
{
break;
}
}
// Check if the content URL was supported
if (!contentUrlSupported)
{
throw new UnsupportedContentUrlException(this, contentUrl);
}
return contentUrlExists;
}
finally
{
readLock.unlock();
}
}
public ContentWriter getWriter(ContentContext ctx)
{
// get the writer
ContentWriter writer = primaryStore.getWriter(ctx);
return writer;
}
/**
* Performs a delete on the local store and if outbound replication is on, propogates
* the delete to the other stores too.
*
* @return Returns the value returned by the delete on the primary store.
*/
public boolean delete(String contentUrl) throws ContentIOException
{
// delete on the primary store
boolean deleted = primaryStore.delete(contentUrl);
if (logger.isDebugEnabled())
{
logger.debug("Deleted content for URL: " + contentUrl);
}
return deleted;
}
}