Skip to content

Conversation

@cgivre
Copy link
Contributor

@cgivre cgivre commented Jul 24, 2024

DRILL-8504: Add Schema Caching to Splunk Plugin

Description

Whenever Drill executes a Splunk query, it must retrieve a list of indexes from Splunk. This step can add a considerable amount of time to the planning phase. This PR introduces a simple in-memory cache for the Splunk plugin which caches the list of indexes to avoid having to query Splunk repeatedly to obtain this information.

This PR also makes a few unrelated minor improvements:

  • Updates the test container to Splunk version 9.3 which at the time of writing is the most current version. I had to update some unit tests as a result.
  • Adds a new config option for the maximum columns returned in Splunk
  • Adds the actual SPL sent to Splunk to the query plan. This can be useful for debugging.

Documentation

(Added to README)
For every query that you send to Splunk from Drill, Drill will have to pull schema information from Splunk. If you have a lot of indexes, this process can cause slow planning time. To improve planning time, you can configure Drill to cache the index names so that it does not need to make additional calls to Splunk.

There are two configuration parameters for the schema caching: maxCacheSize and cacheExpiration. The maxCacheSize defaults to 10k bytes and the cacheExpiration defaults to 1024 minutes. To disable schema caching simply set the cacheExpiration parameter to a value less than zero.

Testing

Ran all unit tests and tested manually.

@cgivre cgivre self-assigned this Jul 24, 2024
@cgivre cgivre requested a review from jnturton July 25, 2024 16:29
@cgivre cgivre changed the title Add Index Cache to Splunk Plugin DRILL-8504: Add Schema Caching to Splunk Plugin Jul 29, 2024
@cgivre cgivre marked this pull request as ready for review July 29, 2024 15:00
@cgivre cgivre added enhancement PRs that add a new functionality to Drill doc-impacting PRs that affect the documentation dependencies labels Jul 30, 2024
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.3</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we achieve the same thing using Guava's caching? The reason I ask is that we already have this insanely big dependency tree and Guava is already in it...

https://www.baeldung.com/guava-cache

Copy link
Contributor

Choose a reason for hiding this comment

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

But so is caffeine now that I look! So I guess we can ignore this suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jnturton Is that a +1? I somehow broke the versioning when I rebased on the current master, but I'll fix before merging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I got pulled away before I could continue but will complete the review today.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please lift the caffeine.version property from metastore/iceberg-metastore/pom.xml to the root pom and either

  • add caffeine with caffeine.version to dependencyManagement in the root pom and remove version numbers here and in the Iceberg metastore, or
  • make both this pom and Iceberg metastore pom specify <version>${caeffine.version}</version>.

So that we standardise the version of Caffeine that gets pulled in.

@cgivre cgivre force-pushed the splunk_schema_cache branch from af3d11b to f372ad6 Compare August 5, 2024 05:22
@cgivre cgivre force-pushed the splunk_schema_cache branch from 74f6b90 to 0d8364b Compare August 12, 2024 16:47
@cgivre
Copy link
Contributor Author

cgivre commented Aug 25, 2024

@jnturton It looks like the GitHub CI is failing on the Hadoop 2 tests with Hive.

@cgivre cgivre force-pushed the splunk_schema_cache branch from 2ff2983 to fd2549a Compare August 26, 2024 13:00
@cgivre cgivre force-pushed the splunk_schema_cache branch from fd2549a to f8bcc82 Compare October 9, 2024 14:05
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.3</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please lift the caffeine.version property from metastore/iceberg-metastore/pom.xml to the root pom and either

  • add caffeine with caffeine.version to dependencyManagement in the root pom and remove version numbers here and in the Iceberg metastore, or
  • make both this pom and Iceberg metastore pom specify <version>${caeffine.version}</version>.

So that we standardise the version of Caffeine that gets pulled in.

}
// Clear the index cache.
if (useCache) {
cache.invalidate(getNameForCache());
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like it would be more natural (and efficient) for the cache to hold one entry per Splunk index, rather than a single entry containing the list of all indexes. Is there a reason it isn't built that way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jnturton I think that's exactly what it does. The invalidate is just the delete method, so the code there removes any cache entries with that entry. Also as an FYI, the cache adds the username to the index name so that if user translation is enabled, users will not see other users' cache.

Comment on lines +189 to +192
String nameKey = getNameForCache();
if (useCache) {
indexList = cache.getIfPresent(nameKey);
}
Copy link
Contributor

@jnturton jnturton Oct 11, 2024

Choose a reason for hiding this comment

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

@cgivre is the cache really storing one Splunk index per key? Here it looks to me like there's a single cache key, derived from the queryUserName and the plugin name, that holds a list of indexes. Or am I just being confused by the Caffeine API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jnturton ,
I'm sorry, I misspoke. The way I intended the cache to work was that we combine the plugin name + user name to create a key, and the value is a list of indexes. Every time a user adds or drops an index, we have to recreate the cache entry for that plugin/username.

So:

splunk1-cgivre: [index1, index2, index2]
splunk2-cgivre: [index5, index6, index7]
splunk1-jnturton: [index1, index2]

That's what the cache should look like. (In theory)

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, in that case, can I propose

  • a Map of caches with one cache per plugin name + query user and one cache key per Splunk index or
  • a unified cache with one cache key per plugin name + query user + Splunk index name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jnturton I'm remembering why I did it this way. When the plugin is accessed, Drill calls the registerTable method which loads the list of indexes in to memory. From my recollection, all similar storage plugins, do something similar in that they load the schemata into memory when the plugin is first accessed. Here the change I made was to first check the memory cache and if that's not populated, then call the index list from Splunk.

I'm happy to do this as you suggest but I'm a little confused as to what exactly you're asking for.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's go with this implementation. Fine tuning can come later if it's needed.

@cgivre cgivre force-pushed the splunk_schema_cache branch from 74b29c4 to 1d3a872 Compare November 11, 2024 21:57
@cgivre
Copy link
Contributor Author

cgivre commented Nov 15, 2024

@jnturton
Thanks for the advice about the swap file. We got a clean CI run. Are we good to merge?

@cgivre cgivre merged commit 70d6a95 into apache:master Nov 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies doc-impacting PRs that affect the documentation enhancement PRs that add a new functionality to Drill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants