Bug 1027221 - When Guvnor is down, KnowledgeAgent keeps rebuilding kbase from cached files
When Guvnor is down, KnowledgeAgent keeps rebuilding kbase from cached files
Status: VERIFIED
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRE (Expert, Fusion) (Show other bugs)
BRMS 5.3.1
Unspecified Unspecified
unspecified Severity high
: GA
: ---
Assigned To: Mario Fusco
Petr Široký
:
Depends On:
Blocks: 1022758
  Show dependency treegraph
 
Reported: 2013-11-06 06:51 EST by Toshiya Kobayashi
Modified: 2014-02-13 10:09 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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

  None (edit)
Description Toshiya Kobayashi 2013-11-06 06:51:23 EST
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 06:53:31 EST
Created attachment 820295 [details]
DroolsTest.java
Comment 2 Toshiya Kobayashi 2013-11-06 06:54:08 EST
Created attachment 820296 [details]
ChangeSet.xml
Comment 3 Toshiya Kobayashi 2013-11-06 06:55:23 EST
Attached DroolsTest.java and ChangeSet.xml to reproduce the issue.
Comment 4 Toshiya Kobayashi 2013-11-06 07:25:16 EST
Sent a pull request:

https://github.com/droolsjbpm/drools/pull/279
Comment 5 Petr Široký 2014-02-13 10:09:57 EST
Verified fixed in 5.3.1-P05.

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