Bug 1027221 - When Guvnor is down, KnowledgeAgent keeps rebuilding kbase from cached files
Summary: When Guvnor is down, KnowledgeAgent keeps rebuilding kbase from cached files
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRE (Expert, Fusion)
Version: BRMS 5.3.1
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: GA
: ---
Assignee: Mario Fusco
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 1022758
TreeView+ depends on / blocked
 
Reported: 2013-11-06 11:51 UTC by Toshiya Kobayashi
Modified: 2025-02-10 03:34 UTC (History)
2 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2025-02-10 03:34:18 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
DroolsTest.java (3.26 KB, text/x-java)
2013-11-06 11:53 UTC, Toshiya Kobayashi
no flags Details
ChangeSet.xml (533 bytes, text/xml)
2013-11-06 11:54 UTC, Toshiya Kobayashi
no flags Details

Description Toshiya Kobayashi 2013-11-06 11:51:23 UTC
Description of problem:

Assuming you configure KnowledgeAgent/ResourceChangeScanner with ChangeSet.xml to connect to Guvnor. In addition, you configure drools.resource.urlcache to enable local file cache.

When Guvnor is down, KnowledgeAgent keeps rebuilding kbase from cached files every time ResourceChangeScanner scans. This is because lastModified is always greater than lastRead. I added some comments in source codes after "<=" to explain.

UrlResource.java:
=====
    public InputStream getInputStream() throws IOException {
        try {
            long lastMod  = grabLastMod(); <= conn.getLastModified() of HTTP HEAD
            if (lastMod == 0) {
                //we will try the cache...
                if (cacheFileExists()) return fromCache();
            }
            if (lastMod > 0 && lastMod > lastRead) {
                if (CACHE_DIR != null && url.getProtocol().equals("http") || url.getProtocol().equals("https")) {
                    //lets grab a copy and cache it in case we need it in future...
                    cacheStream(); <= A cache file is created. The cache file's lastModified is older than 'lastMod' above
                }
            }
            this.lastRead = lastMod; <= So lastRead is younger than cache file's lastModified
            return grabStream();
        } catch (IOException e) {
            if (cacheFileExists()) {
                return fromCache();
            } else {
                throw e;
            }
        }
    }
=====

ResourceChangeScannerImpl.java:
=====
    public void scan() {
...

            for ( Entry<Resource, Set<ResourceChangeNotifier>> entry : this.resources.entrySet() ) {
                Resource resource = entry.getKey();
                Set<ResourceChangeNotifier> notifiers = entry.getValue();

                if ( !((InternalResource) resource).isDirectory() ) {
                    // detect if Resource has been removed
                    long lastModified = ((InternalResource) resource).getLastModified(); <= In case that Guvnor is down, lastModified is cache file's lastModified.
                    long lastRead = ((InternalResource) resource).getLastRead();
                    
...
                    } else if ( lastRead < lastModified && lastRead >= 0 ) { <= kbase rebuild
                        this.listener.debug( "ResourceChangeScanner modified resource=" + resource + " : " + lastRead + " : " + lastModified );
                        // it's modified
=====


Steps to Reproduce:
1. Start BRMS under GMT timezone (e.g. start with -Duser.timezone=GMT). If you test under other timezones, we need to fix BZ1027216 first.
2. Run a client with KnowledgeAgent
3. Shutdown BRMS

Actual results:

KnowledgeAgent rebuilds kbase from cached files every time ResourceChangeScanner scans.

You will see log messages like:

[2013-11-06 20:46:49,202:debug] KnowledgeAgent rebuilding KnowledgeBase using ChangeSet

Expected results:

KnowledgeAgent doesn't rebuild kbase until the resource in Guvnor is updated.

Additional info:

If packages are large, this would be a severe issue.

Comment 1 Toshiya Kobayashi 2013-11-06 11:53:31 UTC
Created attachment 820295 [details]
DroolsTest.java

Comment 2 Toshiya Kobayashi 2013-11-06 11:54:08 UTC
Created attachment 820296 [details]
ChangeSet.xml

Comment 3 Toshiya Kobayashi 2013-11-06 11:55:23 UTC
Attached DroolsTest.java and ChangeSet.xml to reproduce the issue.

Comment 4 Toshiya Kobayashi 2013-11-06 12:25:16 UTC
Sent a pull request:

https://github.com/droolsjbpm/drools/pull/279

Comment 5 Petr Široký 2014-02-13 15:09:57 UTC
Verified fixed in 5.3.1-P05.

Comment 8 Red Hat Bugzilla 2025-02-10 03:34:18 UTC
This product has been discontinued or is no longer tracked in Red Hat Bugzilla.


Note You need to log in before you can comment on or make changes to this bug.