Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Adds cache name to Redis store cache statements to ease debugging #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
44 changes: 22 additions & 22 deletions src/main/java/org/infinispan/persistence/redis/RedisStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final public class RedisStore implements AdvancedLoadWriteStore
@Override
public void init(InitializationContext ctx)
{
RedisStore.log.info("Redis cache store initialising");
RedisStore.log.info("Initialising Redis store for cache " + ctx.getCache().getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use:
RedisStore.log.info("Initialising Redis store for cache '%s' ", ctx.getCache().getName());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers, I'll get to update the PR later this week.

this.ctx = ctx;
}

Expand All @@ -47,13 +47,13 @@ public void init(InitializationContext ctx)
@Override
public void start()
{
RedisStore.log.info("Redis cache store starting");
RedisStore.log.info("Starting Redis store for cache " + ctx.getCache().getName());

try {
this.connectionPool = RedisConnectionPoolFactory.factory(this.ctx.getConfiguration(), this.ctx.getMarshaller());
}
catch(Exception ex) {
RedisStore.log.error("Failed to initialise the redis store", ex);
RedisStore.log.error("Failed to initialise the Redis store for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
}
Expand All @@ -64,7 +64,7 @@ public void start()
@Override
public void stop()
{
RedisStore.log.info("Redis cache store stopping");
RedisStore.log.info("Stopping Redis store for cache " + ctx.getCache().getName());

if (null != this.connectionPool) {
this.connectionPool.shutdown();
Expand Down Expand Up @@ -101,7 +101,7 @@ public void process(
boolean fetchMetadata
)
{
RedisStore.log.debug("Iterating Redis store entries");
RedisStore.log.debug("Iterating Redis store entries for cache " + ctx.getCache().getName());

final InitializationContext ctx = this.ctx;
final TaskContext taskContext = new TaskContextImpl();
Expand Down Expand Up @@ -137,15 +137,15 @@ public void run() {
}
}
catch (Exception ex) {
RedisStore.log.error("Failed to process the redis store key", ex);
RedisStore.log.error("Failed to process a Redis store key for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
}
});
}
}
catch(Exception ex) {
RedisStore.log.error("Failed to process the redis store keys", ex);
RedisStore.log.error("Failed to process the Redis store keys for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
finally {
Expand Down Expand Up @@ -175,7 +175,7 @@ public void purge(Executor executor, final PurgeListener purgeListener)
@Override
public int size()
{
RedisStore.log.debug("Calculating Redis store size");
RedisStore.log.debug("Fetching the Redis store size for cache " + ctx.getCache().getName());
RedisConnection connection = null;

try {
Expand All @@ -187,9 +187,9 @@ public int size()
// log the anomaly and return the int max size
if (dbSize > Integer.MAX_VALUE) {
RedisStore.log.info(
String.format("Redis store is holding more elements than we can count! " +
"Total number of elements found %d. Limited to returning count as %d",
dbSize, Integer.MAX_VALUE
String.format("The Redis store for cache %s is holding more entries than we can count! " +
"Total number of entries found %d. Limited to returning count as %d",
ctx.getCache().getName(), dbSize, Integer.MAX_VALUE
)
);

Expand All @@ -200,7 +200,7 @@ public int size()
}
}
catch(Exception ex) {
RedisStore.log.error("Failed to fetch element count from the redis store", ex);
RedisStore.log.error("Failed to fetch the entry count for the Redis store for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
finally {
Expand All @@ -218,15 +218,15 @@ public int size()
@Override
public void clear()
{
RedisStore.log.debug("Clearing Redis store");
RedisStore.log.debug("Clearing the Redis store for cache " + ctx.getCache().getName());
RedisConnection connection = null;

try {
connection = this.connectionPool.getConnection();
connection.flushDb();
}
catch(Exception ex) {
RedisStore.log.error("Failed to clear all elements in the redis store", ex);
RedisStore.log.error("Failed to clear the Redis store for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
finally {
Expand All @@ -247,7 +247,7 @@ public void clear()
@Override
public MarshalledEntry load(Object key)
{
RedisStore.log.debug("Loading entry from Redis store");
RedisStore.log.debug("Loading entry from the Redis store for cache " + ctx.getCache().getName());
RedisConnection connection = null;

try {
Expand All @@ -270,7 +270,7 @@ public MarshalledEntry load(Object key)
return this.ctx.getMarshalledEntryFactory().newMarshalledEntry(key, valueBuf, metadataBuf);
}
catch(Exception ex) {
RedisStore.log.error("Failed to load element from the redis store", ex);
RedisStore.log.error("Failed to load entry from the Redis store for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
finally {
Expand All @@ -289,7 +289,7 @@ public MarshalledEntry load(Object key)
@Override
public void write(MarshalledEntry marshalledEntry)
{
RedisStore.log.debug("Writing entry to Redis store");
RedisStore.log.debug("Writing entry to the Redis store for cache " + ctx.getCache().getName());
RedisConnection connection = null;

try {
Expand Down Expand Up @@ -317,7 +317,7 @@ public void write(MarshalledEntry marshalledEntry)
}
}
catch(Exception ex) {
RedisStore.log.error("Failed to write element to the redis store", ex);
RedisStore.log.error("Failed to write entry to the Redis store for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
finally {
Expand All @@ -336,15 +336,15 @@ public void write(MarshalledEntry marshalledEntry)
@Override
public boolean delete(Object key)
{
RedisStore.log.debug("Deleting entry from Redis store");
RedisStore.log.debug("Deleting entry from Redis store for cache " + ctx.getCache().getName());
RedisConnection connection = null;

try {
connection = this.connectionPool.getConnection();
return connection.delete(key);
}
catch(Exception ex) {
RedisStore.log.error("Failed to delete element from the redis store", ex);
RedisStore.log.error("Failed to delete entry from the Redis store for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
finally {
Expand All @@ -363,15 +363,15 @@ public boolean delete(Object key)
@Override
public boolean contains(Object key)
{
RedisStore.log.debug("Checking store for Redis entry");
RedisStore.log.debug("Checking key in Redis store for cache " + ctx.getCache().getName());
RedisConnection connection = null;

try {
connection = this.connectionPool.getConnection();
return connection.exists(key);
}
catch(Exception ex) {
RedisStore.log.error("Failed to discover if element is in the redis store", ex);
RedisStore.log.error("Failed to check key in Redis store for cache " + ctx.getCache().getName(), ex);
throw new PersistenceException(ex);
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ private void parseRedisStoreAttributes(XMLExtendedStreamReader reader, RedisStor
builder.maxRedirections(Integer.parseInt(value));
break;
}

default: {
Parser80.parseStoreAttribute(reader, i, builder);
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ public void testRedisCacheStore() throws Exception
assert store.servers().size() == 2;
}

public void testInheritedCacheStoreAttributes() throws Exception
{
String config = InfinispanStartTag.LATEST +
"<cache-container default-cache=\"default\">" +
" <local-cache name=\"default\">\n" +
" <persistence>\n" +
" <redis-store xmlns=\"urn:infinispan:config:store:redis:"+ InfinispanStartTag.LATEST.majorMinor()+ "\"" +
" shared=\"true\" preload=\"true\" >\n" +
" <redis-server host=\"one\" />\n" +
" </redis-store>\n" +
" </persistence>\n" +
" </local-cache>\n" +
"</cache-container>" +
TestingUtil.INFINISPAN_END_TAG;

RedisStoreConfiguration store = (RedisStoreConfiguration) buildCacheManagerWithCacheStore(config);
assert store.shared();
assert store.preload();
assert store.servers().size() == 1;
}

private StoreConfiguration buildCacheManagerWithCacheStore(final String config)
throws IOException
{
Expand Down