Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion addons/content-index/src/main/conf/conf.d/content-index.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[content-index]
#enabled=false

# This property is used to control if authoritative index is enabled. the authoritative index means:
# in terms of performance consideration, we will use content-index as the one-time check for the content
# access, and if not found in content indexing, will treat it as "no content" and bypass the following access to the storage.
#support.authoritative.indexes=true

# This property is used to enable content index warmer, which will scan all repos and load all artifacts
# into content index when startup.
# index.warmer.enable=true
# index.warmer.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.commonjava.indy.action.IndyLifecycleException;
import org.commonjava.indy.action.ShutdownAction;
import org.commonjava.indy.content.index.conf.ContentIndexConfig;
import org.commonjava.indy.data.StoreDataManager;
import org.commonjava.indy.measure.annotation.Measure;
import org.commonjava.indy.model.core.ArtifactStore;
Expand Down Expand Up @@ -77,6 +78,9 @@ public class DefaultContentIndexManager
@Inject
private Instance<PackageIndexingStrategy> indexingStrategyComponents;

@Inject
private ContentIndexConfig config;

private Map<String, PackageIndexingStrategy> indexingStrategies;

private QueryFactory queryFactory;
Expand All @@ -98,6 +102,12 @@ public DefaultContentIndexManager( StoreDataManager storeDataManager, SpecialPat
@PostConstruct
public void constructed()
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

if ( indexingStrategyComponents != null )
{
Map<String, PackageIndexingStrategy> strats = new HashMap<>();
Expand Down Expand Up @@ -126,6 +136,12 @@ public String getId()
public void stop()
throws IndyLifecycleException
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

logger.debug( "Shutdown index cache" );
contentIndex.stop();
}
Expand All @@ -140,6 +156,12 @@ public int getShutdownPriority()
@Measure
public boolean removeIndexedStorePath( String rawPath, StoreKey key, Consumer<IndexedStorePath> pathConsumer )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return false;
}

String path = getStrategyPath( key, rawPath );
IndexedStorePath topPath = new IndexedStorePath( key, path );
logger.trace( "Attempting to remove indexed path: {}", topPath );
Expand All @@ -158,6 +180,12 @@ public boolean removeIndexedStorePath( String rawPath, StoreKey key, Consumer<In

public String getStrategyPath( final StoreKey key, final String rawPath )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return rawPath;
}

PackageIndexingStrategy strategy = indexingStrategies.get( key.getPackageType() );
if ( strategy == null )
{
Expand All @@ -174,6 +202,12 @@ public String getStrategyPath( final StoreKey key, final String rawPath )
@Measure
public void deIndexStorePath( final StoreKey key, final String rawPath )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

String path = getStrategyPath( key, rawPath );
IndexedStorePath toRemove = new IndexedStorePath( key, path );
IndexedStorePath val = contentIndex.remove( toRemove );
Expand All @@ -184,6 +218,12 @@ public void deIndexStorePath( final StoreKey key, final String rawPath )
@Measure
public StoreKey getIndexedStoreKey( final StoreKey key, final String rawPath )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return null;
}

String path = getStrategyPath( key, rawPath );
IndexedStorePath ispKey = new IndexedStorePath( key, path );
IndexedStorePath val = contentIndex.get( ispKey );
Expand All @@ -204,6 +244,12 @@ public StoreKey getIndexedStoreKey( final StoreKey key, final String rawPath )
@Measure
public void indexTransferIn( Transfer transfer, StoreKey...topKeys )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

if ( transfer != null && transfer.exists() )
{
StoreKey key = LocationUtils.getKey( transfer );
Expand All @@ -219,6 +265,12 @@ public void indexTransferIn( Transfer transfer, StoreKey...topKeys )
@Measure
public void indexPathInStores( String rawPath, StoreKey originKey, StoreKey... topKeys )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

String path = getStrategyPath( originKey, rawPath );

IndexedStorePath origin = new IndexedStorePath( originKey, path );
Expand All @@ -237,6 +289,12 @@ public void indexPathInStores( String rawPath, StoreKey originKey, StoreKey... t
@Measure
public void clearAllIndexedPathInStore( ArtifactStore store )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

StoreKey sk = store.getKey();

long total = iterateRemove( () -> queryFactory.from( IndexedStorePath.class )
Expand All @@ -259,6 +317,12 @@ public void clearAllIndexedPathInStore( ArtifactStore store )
@Measure
public void clearAllIndexedPathWithOriginalStore( ArtifactStore originalStore )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

StoreKey osk = originalStore.getKey();

long total = iterateRemove( () -> queryFactory.from( IndexedStorePath.class )
Expand Down Expand Up @@ -303,6 +367,12 @@ private long iterateRemove( final Supplier<Query> queryFunction )
@Measure
public void clearAllIndexedPathInStoreWithOriginal( ArtifactStore store, ArtifactStore originalStore )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

StoreKey sk = store.getKey();
StoreKey osk = originalStore.getKey();

Expand Down Expand Up @@ -337,6 +407,12 @@ public void clearAllIndexedPathInStoreWithOriginal( ArtifactStore store, Artifac
@Measure
public void clearIndexedPathFrom( String rawPath, Set<Group> groups, Consumer<IndexedStorePath> pathConsumer )
{
if ( !config.isEnabled() )
{
logger.debug( "Content indexing is disabled." );
return;
}

if ( groups == null || groups.isEmpty() )
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
public abstract class IndexingContentManagerDecorator
implements ContentManager
{
private final Logger logger = LoggerFactory.getLogger( this.getClass() );
private final Logger logger = LoggerFactory.getLogger( IndexingContentManagerDecorator.class.getName() );

@Inject
private StoreDataManager storeDataManager;
Expand Down Expand Up @@ -296,9 +296,10 @@ else if ( StoreType.hosted != type ) // don't track NFC for hosted repos
}
}

logger.trace( "Delegating retrieve call for concrete repository: {}/{}", store, path );
transfer = delegate.retrieve( store, path, eventMetadata );

if ( exists( transfer ) )
if ( exists( transfer ) && indexCfg.isEnabled() )
{
logger.debug( "Got transfer from delegate: {} (will index)", transfer );
indexManager.indexTransferIn( transfer, store.getKey() );
Expand Down Expand Up @@ -338,8 +339,13 @@ private Transfer getTransferFromConstituents( Collection<StoreKey> constituents,
if ( exists( transfer ) )
{
nfc.clearMissing( resource );
logger.debug( "Got transfer from constituent: {} (will index)", transfer );
indexManager.indexTransferIn( transfer, parentStore.getKey() );

if ( indexCfg.isEnabled() )
{
logger.debug( "Got transfer from constituent: {} (will index)", transfer );
indexManager.indexTransferIn( transfer, parentStore.getKey() );
}

return transfer;
}
}
Expand All @@ -358,11 +364,17 @@ private boolean exists( final Transfer transfer )
return transfer != null && transfer.exists();
}

@Measure( timers = @MetricNamed( DEFAULT ), exceptions = @MetricNamed( DEFAULT ) )
@Measure
public Transfer getIndexedTransfer( final StoreKey storeKey, final StoreKey topKey, final String path,
final TransferOperation op, final EventMetadata metadata )
throws IndyWorkflowException
{
if ( !indexCfg.isEnabled() )
{
logger.debug( "Content indexing is disabled. Returning null for indexedTransfer of: {}/{}", storeKey, path );
return null;
}

logger.debug( "Looking for indexed path: {} in: {} (entry point: {})", path, storeKey, topKey );

try
Expand Down Expand Up @@ -489,7 +501,7 @@ else if ( isAuthoritativelyMissing( store ) )

transfer = delegate.getTransfer( store, path, op );
// index the transfer only if it exists, it cannot be null at this point
if ( exists( transfer ) )
if ( exists( transfer ) && indexCfg.isEnabled() )
{
indexManager.indexTransferIn( transfer, store.getKey() );
}
Expand Down Expand Up @@ -541,7 +553,11 @@ public Transfer getIndexedMemberTransfer( final Group group, final String path,

if ( transfer != null )
{
indexManager.indexTransferIn( transfer, key, topKey );
if ( indexCfg.isEnabled() )
{
indexManager.indexTransferIn( transfer, key, topKey );
}

return transfer;
}
else if ( StoreType.group == key.getType() )
Expand Down Expand Up @@ -618,7 +634,7 @@ public Transfer getTransfer( final StoreKey storeKey, final String path, final T
}

transfer = delegate.getTransfer( storeKey, path, op );
if ( exists( transfer ) )
if ( exists( transfer ) && indexCfg.isEnabled() )
{
logger.debug( "Indexing transfer: {}", transfer );
indexManager.indexTransferIn( transfer, storeKey );
Expand Down Expand Up @@ -683,8 +699,11 @@ public Transfer store( final ArtifactStore store, final String path, final Input
Transfer transfer = delegate.store( store, path, stream, op, eventMetadata );
if ( transfer != null )
{
logger.trace( "Indexing: {} in: {}", transfer, store.getKey() );
indexManager.indexTransferIn( transfer, store.getKey() );
if ( indexCfg.isEnabled() )
{
logger.trace( "Indexing: {} in: {}", transfer, store.getKey() );
indexManager.indexTransferIn( transfer, store.getKey() );
}

if ( store instanceof Group )
{
Expand All @@ -697,7 +716,7 @@ public Transfer store( final ArtifactStore store, final String path, final Input
try
{
Set<Group> groups = storeDataManager.query().getGroupsAffectedBy( store.getKey() );
if ( groups != null && !groups.isEmpty() )
if ( groups != null && !groups.isEmpty() && indexCfg.isEnabled() )
{
groups.forEach( g -> indexManager.deIndexStorePath( g.getKey(), path ) );
}
Expand Down Expand Up @@ -731,15 +750,22 @@ public Transfer store( final List<? extends ArtifactStore> stores, final StoreKe
Transfer transfer = delegate.store( stores, topKey, path, stream, op, eventMetadata );
if ( transfer != null )
{
indexManager.indexTransferIn( transfer, topKey );
if ( indexCfg.isEnabled() )
{
indexManager.indexTransferIn( transfer, topKey );
}

try
{
ArtifactStore topStore = storeDataManager.getArtifactStore( topKey );
nfc.clearMissing( new ConcreteResource( LocationUtils.toLocation( topStore ), path ) );
// We should deIndex the path for all parent groups because the new content of the path
// may change the content index sequence based on the constituents sequence in parent groups
indexManager.deIndexStorePath( topKey, path );

if ( indexCfg.isEnabled() )
{
// We should deIndex the path for all parent groups because the new content of the path
// may change the content index sequence based on the constituents sequence in parent groups
indexManager.deIndexStorePath( topKey, path );
}
}
catch ( IndyDataException e )
{
Expand All @@ -764,7 +790,7 @@ public boolean delete( final ArtifactStore store, final String path, final Event
throws IndyWorkflowException
{
boolean result = delegate.delete( store, path, eventMetadata );
if ( result )
if ( result && indexCfg.isEnabled() )
{
indexManager.deIndexStorePath( store.getKey(), path );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.commonjava.indy.conf.IndyConfigInfo;
import org.commonjava.propulsor.config.annotation.ConfigName;
import org.commonjava.propulsor.config.annotation.SectionName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import java.io.InputStream;
Expand All @@ -31,16 +33,22 @@ public class ContentIndexConfig

public static final String AUTH_INDEX_PARAM = "support.authoritative.indexes";

public static final String ENABLE_INDEX_WARMER = "index.warmer.enable";
public static final String ENABLE_INDEX_WARMER = "index.warmer.enabled";

private static final String ENABLE = "enabled";

private static final Boolean DEFAULT_AUTHORITATIVE_INDEXES = Boolean.FALSE;

private static final Boolean DEFAULT_WARMER_ENABLED = Boolean.FALSE;

private static final Boolean DEFAULT_ENABLED = Boolean.FALSE;

private Boolean authoritativeIndex;

private Boolean warmerEnabled;

private Boolean enabled;

public ContentIndexConfig()
{
}
Expand Down Expand Up @@ -83,4 +91,20 @@ public InputStream getDefaultConfig()
{
return Thread.currentThread().getContextClassLoader().getResourceAsStream( "default-content-index.conf" );
}

public boolean isEnabled()
{
Boolean result = enabled == null ? DEFAULT_ENABLED : enabled;

Logger logger = LoggerFactory.getLogger( getClass() );
logger.debug( "Is content indexer enabled? {}", result );

return result;
}

@ConfigName( ContentIndexConfig.ENABLE )
public void setEnabled( Boolean enabled )
{
this.enabled = enabled;
}
}
Loading