[
https://issues.apache.org/jira/browse/DERBY-5894?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Knut Anders Hatlen updated DERBY-5894:
--------------------------------------
Attachment: d5894-1b-minimal-privileges.diff
d5894-1a-minimal-change.diff
I'm attaching two alternative fixes for this issue.
d5894-1a-minimal-change.diff implements the minimal change to resolve the race
condition. It makes backupContainer() have its own privileged action, so that
there's no state shared with the other privileged operations, and hence no
synchronization needed since there is no race.
However, the current approach (not changed by the 1a patch) invokes the entire
privBackupContainer() method in a privileged block. It's a relatively big
method, and only some portions actually need to run with privileges.
The alternative patch d5894-1b-minimal-privileges.diff changes
backupContainer() so that it doesn't invoke all code in a privileged block.
Instead, it uses helper methods with small privileged blocks that do as little
as possible apart from invoking the operations that need privileges. In some
cases existing helper methods could be used, but it also needed to add some new
ones (for copying a file, removing a file, and creating a RandomAccessFile).
Although the 1b patch adds more code than the 1a patch, I prefer the 1b patch,
as it reduces the risk of accidentally giving permissions to code that's not
supposed to have them. Both patches should solve the race condition, as they
both ensure that backupContainer() does not use any shared state without
synchronization. (I haven't reproduced the NPE, though, so I can't verify it.)
Regression tests ran cleanly with both of the patches.
> NPE in OnlineBackupTest1 while backing up in stubFileToRemoveAfterCheckPoint
> ----------------------------------------------------------------------------
>
> Key: DERBY-5894
> URL: https://issues.apache.org/jira/browse/DERBY-5894
> Project: Derby
> Issue Type: Bug
> Components: Store
> Reporter: Dag H. Wanvik
> Assignee: Knut Anders Hatlen
> Labels: derby_triage10_10
> Attachments: d5894-1a-minimal-change.diff,
> d5894-1b-minimal-privileges.diff, d5894.zip
>
>
> Saw this while running OnlineBackupTest1 trying to repro DERBY-973.
> ERROR 38000: The exception 'java.lang.NullPointerException' was thrown while
> evaluating an expression.
> at
> org.apache.derby.iapi.error.StandardException.newException(StandardException.java:288)
> at
> org.apache.derby.iapi.error.StandardException.unexpectedUserException(StandardException.java:575)
> at
> org.apache.derby.impl.services.reflect.ReflectMethod.invoke(ReflectMethod.java:63)
> at
> org.apache.derby.impl.sql.execute.CallStatementResultSet.open(CallStatementResultSet.java:75)
> at
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:443)
> at
> org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:324)
> at
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1242)
> at
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1715)
> at
> org.apache.derby.impl.jdbc.EmbedCallableStatement.executeStatement(EmbedCallableStatement.java:118)
> at
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.execute(EmbedPreparedStatement.java:1370)
> at
> org.apache.derbyTesting.functionTests.tests.store.OnlineBackup.performBackup(OnlineBackup.java:89)
> at
> org.apache.derbyTesting.functionTests.tests.store.OnlineBackup.run(OnlineBackup.java:60)
> at java.lang.Thread.run(Thread.java:637)
> Caused by: java.lang.NullPointerException
> at java.util.Hashtable.put(Hashtable.java:401)
> at
> org.apache.derby.impl.store.raw.data.BaseDataFileFactory.stubFileToRemoveAfterCheckPoint(BaseDataFileFactory.java:1613)
> at
> org.apache.derby.impl.store.raw.data.RAFContainer.run(RAFContainer.java:1651)
> at java.security.AccessController.doPrivileged(Native Method)
> at
> org.apache.derby.impl.store.raw.data.RAFContainer.backupContainer(RAFContainer.java:983)
> at
> org.apache.derby.impl.store.raw.data.BaseContainerHandle.backupContainer(BaseContainerHandle.java:1031)
> at
> org.apache.derby.impl.store.raw.data.BaseDataFileFactory.backupDataFiles(BaseDataFileFactory.java:2466)
> at org.apache.derby.impl.store.raw.RawStore.backup(RawStore.java:978)
> at org.apache.derby.impl.store.raw.RawStore.backup(RawStore.java:649)
> at
> org.apache.derby.impl.store.access.RAMAccessManager.backup(RAMAccessManager.java:964)
> at
> org.apache.derby.impl.db.BasicDatabase.backup(BasicDatabase.java:430)
> at
> org.apache.derby.catalog.SystemProcedures.SYSCS_BACKUP_DATABASE(SystemProcedures.java:961)
> at
> org.apache.derby.exe.acf33d40c7x0138x6d7cx6df3x0000720ad17b0.g0(Unknown
> Source)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:592)
> at
> org.apache.derby.impl.services.reflect.ReflectMethod.invoke(ReflectMethod.java:46)
> ... 10 more
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira