You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Sunitha Kambhampati <ks...@gmail.com> on 2005/04/30 01:15:25 UTC
[PATCH] Derby 218 - Add relaxed durability option
A little background: Sometime earlier on the list, Dan posted a fix to
make derby go faster with relaxed durability with some flags. The post
is at
http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
This mode is very useful for unit testing or at development time when
recoverability is not required.
Basically in this mode, syncs are disabled for logs, data writes at
checkpoint, page allocation when file is grown; - what this means is
that data is not flushed all the way to the disk and in most cases i/o
cost is not involved. Note, code already exists in Derby to do this.
So for Derby 218, This patch addresses the following requirements:
1) Have a single property to enable this relaxed durability mode, so it
is easy for users to enable it.
2) Print message to derby.log that this mode is enabled
3) A way to report boot errors that may be because of this option being
enabled. What this maps to is - have a marker to recognize that database
was booted in this mode, and then on subsequent boot; if errors happen
during recovery - report a message that it could have happened because
of this mode being set.
Changes are not much.
svn stat
M java\engine\org\apache\derby\impl\store\raw\log\LogToFile.java
M
java\engine\org\apache\derby\impl\store\raw\data\BaseDataFileFactory.java
M java\engine\org\apache\derby\impl\store\raw\data\RAFContainer.java
M java\engine\org\apache\derby\iapi\reference\MessageId.java
M java\engine\org\apache\derby\iapi\reference\Property.java
M java\engine\org\apache\derby\loc\messages_en.properties
A
java\testing\org\apache\derbyTesting\functionTests\tests\store\TestNoSyncMode.java
M
java\testing\org\apache\derbyTesting\functionTests\tests\store\copyfiles.ant
A
java\testing\org\apache\derbyTesting\functionTests\tests\store\TestNoSyncMode_derby.properties
A
java\testing\org\apache\derbyTesting\functionTests\master\TestNoSyncMode.out
M
java\testing\org\apache\derbyTesting\functionTests\suites\storemats.runall
Since this is a longish email , for those who may not read the rest of
it, here are the testing results
Testing results:
- I ran derbyall with 1.4.2 jvm and all tests passed.
- I ran the storeall suite separately both with setting the
derby.system.testMode property to true and without it.
with this property set, the storeall suite ran about 2 times as fast.
-------------------------------
Below I explain how the patch addresses the above requirements and try
to provide details on how I went about making those changes
0) Note
1) A single property has been added to enable this relaxed durability
option. The property name is derby.system.testMode and takes in value
true or false. By default it is false. It can be set as a command line
option to the JVM when starting the application or within the
application or in the derby.properites file. Property is loaded at boot
time, so for it to have an effect you need to enable it at boot time.
More comments added in code itself. see variable TESTMODE_NO_SYNC =
"derby.system.testMode"; in Property.java.
(In this patch, I have used 'no_sync' as suffix in variable names
because I think with respect to store - that is what this mode is all
about - disabling syncs for the cases already mentioned earlier in this
mail)
I chose the property name derby.system.testMode for this
- represents a higher concept as to when one would use relaxed
durability (no sync) option.
- mostly it should be enabled only when data is not important and
ideally maybe for testing and development purposes,
- also with the hope that the word 'testMode' would prompt users to
look this property up before using it in a production like environment
where it may not necessarily be appropriate.
Code changes for this:
- Added this new property derby.system.testMode in
java\engine\org\apache\derby\iapi\reference\Property.java
- Removed the following properties from Property.java as they are no
longer required.
derby.storage.dataNotSyncedAtCheckPoint=true ( I'll refer to this
as DNSAC in notes below)
derby.storage.dataNotSyncedAtAllocation=true ( I'll refer to
this as DNSAA in notes below)
derby.storage.logNotSynced=true (I'll refer to this as
LNS in notes below)
- Previously code existed for enabling the DNSAC, DNSAA and LNS options
conditional on Performance.MEASURE
So how it works is , the 2 variables in BaseDataFileFactory.java are
used to control if syncs happen or not for data pages at allocation and
at checkpoint.
dataNotSyncedAtAllocation
dataNotSyncedAtCheckpoint
And in java/engine/org/apache/derby/impl/store/raw/log/LogToFile, the
logNotSynced variable is used to control if syncs happen for the logs
are not.
These variables are enabled (set to true) if Performance.MEASURE is set
to true, and if the DNSAC, and DSNAA propertie are enabled.
So all that is required now is
- remove conditional on Performance.MEASURE in these cases, instead use
the derby.system.testMode property to enable them . This happens in the
boot methods
- make sure to remove any conditionals on Performance.MEASURE that is
used to disable syncs but instead control it by the variables mentioned
above.. ie e.g. dataNotSyncedAtAllocation in BaseDataFileFactory.java ...
- remove reading of the DNSAC, DNSAA,LNS property as they are not needed
anymore
Changes were needed to following files -
i)
java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
(check boot method)
ii) java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
iii) java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
(check boot method).
2) Write to the derby.log a warning message
Needed to add a new message.
Messages need to be translated, so I made the following changes
i) added a variable in
java/engine/org/apache/derby/iapi/reference/MessageId.java to represent
this new message.
String STORE_TESTMODE_NO_SYNC = "D013";
ii) Message content added to
java/engine/org/apache/derby/loc/messages_en.properties
D013=WARNING: {0} is set to true. In this mode, there is no guarantee
that the system will recover a system crash or JVM termination. Enable
this property only when there is no need for recoverability \n
iii) In the boot process, rawstore boot calls logfactory boot, so the
first time the derby.system.testMode property is read, it is in
rawstore, so added code to print the warning message in
BaseDataFileFactory.boot(..)
3) A way to report boot errors that may be because of this option being
enabled. What this maps to is - have a marker to recognize that database
was booted in this mode, and then on subsequent boot if errors happen
during recovery report a message that it could have happened because of
this mode being set.
- To write a marker out , log.ctrl file is used, it has a few spare
bytes so no major changes needed here. ( ie no disk format changes.... )
Check the method readControlFile in
java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
- Used the first spare byte available in log control file which will be
used to store information about if derby.system.testMode is set or not.
Added variable TESTMODE_NO_SYNC_FLAG_OFFSET to represent this offset in
LogToFile.java
- The value written out if this property is enabled is
TESTMODE_NO_SYNC_TRUE = 0x1 else a 0 is written out.
( I didnt like to put the 0 but wasnt feeling too strong to adding a new
static byte variable either.. and as rest of the code around it in
writeControlFile seems to use 0 as is , I just followed the same approach).
- Change made to readControlFile to read in the value for the testmode
case when Logfactory is booted, the flag is read and value stored
in variable called wasDBInTestModeNoSync. This variable keeps track of
if database was previously booted in the derby.system.testMode or not.
Comes in use for error reporting.
- Also added a message to report to the derby.log incase database was
previously booted with derby.system.testMode set to true. Change to
messages_en.properties and MessageId.java.
L020=WARNING: The database was previously booted with {0} set to true.
Note that this mode {0}=true does not guarantee recoverability \n
little on the flow with respect to writeControlFile .. if you look at
the code in LogToFile for boot and recover, writeControlFile is called a
couple of times.. to read the checkpoint instant etc..
- For my changes, I am just copy/paste the comments from
writeControlFile(...) , Note case4 below .. which is the interesting one.
// A spare byte at offset TESTMODE_NO_SYNC_FLAG_OFFSET
// is used to write out if database was in
derby.system.testMode=true mode
// or not.
// This byte will have one of the two values
// - TESTMODE_NO_SYNC_TRUE to represent database was booted
// in this mode
// - 0 to represent database was not booted in this mode
//
// The sole purpose of this flag in control file is to help
// identify any recovery problems that might happen as a result
of this
// mode being set.
//
// Possible scenarios. In table below, cases are listed giving
// the value of derby.system.testMode if it was enabled or not
at boot time
// ---------------------------------------------------------------
// Case Previous Current Action , what should
the flag be set to in log.ctrl
// Boot Boot file
// --------------------------------------------------------------
// 1 - true write
TESTMODE_NO_SYNC_TRUE
// 2 - false write 0
// 3 false false write 0
// 4 true false write
TESTMODE_NO_SYNC_TRUE
// 5 true true write
TESTMODE_NO_SYNC_TRUE
//
// Case 4 is the interesting case here.
// one cannot write out the derby.system.testMode is disabled
just yet
// because it is possible that the database recovery might fail
and on subsequent
// restarts this state would be lost. So only when recovery is
successful, will
// we update the flag in the log control file to indicate that
the derby.system.testMode
// is not enabled. (This will happen at the end of recovery ,
see recover method)
//
// Case 1, 2 is when database is created fresh with this
property enabled.
//
// wasDBInTestModeNoSync has information if database was
previously booted
// in derby.system.testMode=true mode
To handle case 4, changes went into recover () method , if database
recovery is successful only then we update the flag in the control file
to say database is not booted with this property enabled. Since there
was no method available to update the log control file, added a new
method updateTestModeFlagInCtrlFile(byte value) to do that.
So now that changes are done to write the marker to the control file and
to read it, it is necessary to take care of case when error happens.
- added a new message to report that cause of an error could be related
to this property being set
added a new variable in MessageId.LOG_TESTMODE_NO_SYNC_ERR in
java/engine/org/apache/derby/iapi/reference/MessageId.java
and the message to java/engine/org/apache/derby/loc/messages_en.properties
L021=WARNING: The database was either previously booted or is currently
booted with {0} set to true. Note that this mode {0}=true does not
guarantee recoverability, and is probably what might have caused this
boot error \n
- added MessageId.LOG_TESTMODE_NO_SYNC_ERR in
java/engine/org/apache/derby/iapi/reference/MessageId.java
Added a new method logErrMsgForTestModeNoSync() in LogToFile.java to
print out this message if any error happens when database is in the
influence of this property.
In deciding what the best place would be to call the
logErrMsgForTestModeNoSync, I debated between adding it in markCorrupt()
versus logErrMsg(..). It seemed like if error happened during boot -
the flow was to call markCorrupt which would call logErrMsg. Some error
messages seem to call logErrMsg(..) directly. So I picked the
logErrMsg as it covered most of the errors thrown during boot/recovery
that would be related to something with this property being set.
-------------------------------------------
TESTING
1) I added one new java file per the derby test harness, to test the
following
- check if the property is enabled correctly by timing some inserts
into a table.
- check if the correct flag (TESTMODE_NO_SYNC_TRUE) is written out
into the log.ctrl file
- check if the derby.log has the warning message.
Changes include
i)Added new test to
java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
ii)Added
java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
TestNoSyncMode_derby.properties has
derby.system.testMode=true
This property file is needed so when test is run it picks up this property.
iii)The TestNoSyncMode_derby.properties is added to copyfiles.ant so it
will be copied over when compiling derby tests.
iv) To enable this new test as part of the store suite, I modified the
java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
added store/TestNoSyncMode.java
v) To get my correct output file, first i just put an initial empty file
in
java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
Ran the test after compiling source; java
org.apache.derbyTesting.functionTests.harness.RunTest
store/TestNoSyncMode.java
Then I updated the out file in the master directory, after checking if
the TestNoSyncMode.out file was correct.
2) For the error messages on a boot error, it is difficult to put it in
a test, so I checked this in the debugger and it works ok.
Meanwhile, Suresh Thalamati posted on the list that he is working on a
corruptible storage factory, once that is there - I am hoping I could
use that to have a test to check the error messages for boot errors.
As far as I can tell, this does not affect upgrade and such since we are
not changing the disk format etc.. ..There is one spare byte in
log.ctrl file that is being used now as a result of this change and
this byte value should not have been used to represent anything useful
by any earlier version
Testing results (already mentioned in the beginning of this email).
Please give your comments.
Thanks,
Sunitha.
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Sunitha Kambhampati <ks...@gmail.com>.
Thanks for the feedback.
Øystein Grøvlen wrote:
> <>Even if it is a bit late, here are some questions/commentsto this
> patch and the follow-up patch for the test program:
>
> - I am not sure about the value of this mode compared to a mode with
> relaxed durability, but guaranteed consistency. The large
> performance improvements comes from not syncing transaction
> commit. How much extra performance do you really get from not
> doing one sync per checkpoint?
I think both the options
1) derby.system.durability=test
2)actual relaxed durability with consistency and recoverability
are useful. I would probably use 1 for testing purposes and earlier
responses to the list seemed to indicate #1 was good to support.
I agree with you that #2 is a good and useful option to have and I think
other databases support this option.
> <>
> - Unless I am missing something, it does not seem more difficult to
> implement the alternative that guarantees consistency. Do you
> have any plans to do that?
>
I have filed a jira issue (Derby-306). But I am tied up with other
things at the moment so I dont have plans to do this right now.
> <> - With respect to upgrade, does previous versions properly
> initialize the spare byte in the log.ctrl file? Otherwise, one
> could risk false detections on upgrade.
-- the spare byte (that I used in my initial patch) is initialized
correctly in previous version., but in the final patch per review
comments - the log control flags byte was used to store this flag and
yes it is initialized in previous versions correctly. So I think there
should not be any false detections on upgrade.
> <>
> - I am a bit sceptical to the value of having a test that tests that
> this feature give a certain performance advantage. I have seen
> that over time such tests often have false failures when run on
> new platforms. I see that your latest patch addresses this.
> However, should the performance of disk io increase beyond your
> threshold, the test would not be able to detect any failures to
> turn off syncing.I think that a performance regression test
> would be better for this prupose.
Yes, you are right. The best way to detect issues with this case would
be a performance regression test. This test was (is) tricky :)
specially adding the timing part as a functional test.. But I think
currently what the test does will atleast send off an alarm if the
inserts take really long. I added lots of comments in the test and as
well as when the test might fail with warnings about it being
approximate times.
But since we dont require any perf test to be run when submitting
patches, I think maybe this test is probably ok for now ..
I welcome any suggestions on this to make it better..
Thanks,
Sunitha.
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Øystein Grøvlen <Oy...@Sun.COM>.
>>>>> "SK" == Sunitha Kambhampati <ks...@gmail.com> writes:
SK> A little background: Sometime earlier on the list, Dan posted a fix to
SK> make derby go faster with relaxed durability with some flags. The
SK> post is at
SK> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
I was originally planning to review this before it was committed, but
I did not get around to sending my comments before I went on a
vacation. Even if it is a bit late, here are some questions/comments
to this patch and the follow-up patch for the test program:
- I am not sure about the value of this mode compared to a mode with
relaxed durability, but guaranteed consistency. The large
performance improvements comes from not syncing transaction
commit. How much extra performance do you really get from not
doing one sync per checkpoint?
- Unless I am missing something, it does not seem more difficult to
implement the alternative that guarantees consistency. Do you
have any plans to do that?
- With respect to upgrade, does previous versions properly
initialize the spare byte in the log.ctrl file? Otherwise, one
could risk false detections on upgrade.
- I am a bit sceptical to the value of having a test that tests that
this feature give a certain performance advantage. I have seen
that over time such tests often have false failures when run on
new platforms. I see that your latest patch addresses this.
However, should the performance of disk io increase beyond your
threshold, the test would not be able to detect any failures to
turn off syncing. I think that a performance regression test
would be better for this prupose.
- The test will only test whether the syncing at commit is turned
off. The other syncs will not decrease performance so much that
it would be detected by the threshold of the test.
--
�ystein
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Mike Matrigali <mi...@sbcglobal.net>.
this seems fine with me. I agree none does not seem right, none seems
more appropriate if an in memory implementation is ever provided -
though derby.system.durability=memory seems better than none in that
case.
I like that a setting that says "test" forces someone to think about
what they are setting - and hopefully look up what the consequences
can be.
Sunitha Kambhampati wrote:
> I like this name : derby.system.durability=test
>
> I will wait for Suresh's comments and then change the name of the
> property after that unless someone else has a better suggestion.
>
> Thanks for your input.
> Sunitha.
>
> David Van Couvering wrote:
>
>> I think testMode isn't very clear what it's doing. I agree that
>> relaxedDurability is not correct because it doesn't communicate that
>> you may not be able to boot the database.
>>
>> How about derby.system.fast-and-loose :)
>>
>> Seriously, how about
>>
>> derby.system.durability=test
>>
>> (you can't really say "none" because data pages are being written to
>> disk)
>>
>> or derby.system.durability.testMode=true
>>
>> I personally like derby.system.durability=test, because then later we
>> can add derby.system.durability=relaxed for true relaxed durability
>> where the database is durable, and derby.system.durability=none for
>> when we implement in-memory storage.
>>
>> David
>>
>> Sunitha Kambhampati wrote:
>>
>>> This patch disables syncs for
>>> - 1)the log file at each commit
>>> - 2)the log file before data page makes it to disk
>>> - 3)data page allocation when file is grown
>>> - 4)data writes during checkpoint.
>>>
>>> Thus, when this mode is enabled, syncs are not enforcing proper WAL
>>> protocol and might lead to database not being able to boot. Also
>>> earlier when I did a search on the web for the term relaxed
>>> durability , it seemed to me that the term was used for cases when it
>>> is ok to lose committed transactions but the database should be able
>>> to boot successfully.
>>>
>>> So does derby.system.testMode seem ok given that it might not be
>>> appropriate in a production like environment...
>>>
>>> Or, maybe another name -
>>>
>>> call this mode of no syncs as derby.system.durable=none ( or
>>> derby.storage.durable=none).
>>> and in the future when someone implements the case that was discussed
>>> earlier on list
>>> (http://mail-archives.apache.org/mod_mbox/db-derby-dev/200504.mbox/%3c425C6489.4070205@sbcglobal.net%3e
>>> ) where only #1 and #3 syncs are disabled, that would ensure that
>>> database would boot ok, with losing some committed transactions, this
>>> setting could be derby.system.durable=partial or something similar.
>>>
>>> Any comments.
>>>
>>> Thanks,
>>> Sunitha.
>>>
>>> David Van Couvering wrote:
>>>
>>>> After I wrote my email, I wondered if the feature as currently
>>>> implemented wasn't quite what I was thinking we should have. I
>>>> agree that if you potentially can't boot your database, this is not
>>>> a production-level feature.
>>>>
>>>> I second the motion to see more work done to implement the relaxed
>>>> durability option that guarantees a bootable database, that's what I
>>>> was thinking of when I sent my previous email.
>>>>
>>>> Thanks,
>>>>
>>>> David
>>>>
>>>> Mike Matrigali wrote:
>>>>
>>>>> As I have posted before I have concerns about this mode, as it can
>>>>> definitely produce a database which can not boot. But the discussions
>>>>> here convinced me
>>>>> that it was useful for a number of applications, so now believe it
>>>>> should be checked in. I definitely have no career path in marketing
>>>>> as my first take at a name was corrupt_your_db=true :-) . So testMode
>>>>> seemed ok to me, but if another name is better that is fine with me
>>>>> also.
>>>>>
>>>>> Going forward I would like to see more work done to implement the
>>>>> relaxed durability option suresh and I were discussing. I believe
>>>>> that with some code changes file allocation, log write and many of
>>>>> the data write sync's can be eliminated and still guarantee a bootable
>>>>> database. This mode would not guarantee a committed transaction,
>>>>> but would guarantee that database on a disk with enough free space
>>>>> would boot and that the db would represent only complete
>>>>> transactions (either fully applied or not). This option would
>>>>> be slower than what is available from this patch so I believe both
>>>>> features are useful.
>>>>>
>>>>> David Van Couvering wrote:
>>>>>
>>>>>> Hi, Sunitha. Thanks for your work on this. My comment is more a
>>>>>> "marketing" comment than a technical one. I disagree that this is
>>>>>> useful only for testing and development. As I mentioned in
>>>>>> previous emails, there are a number of customers who may find this
>>>>>> very useful indeed, who are willing to trade off 100% guarantee of
>>>>>> all transactions being available on recovery for significant
>>>>>> increases in performance.
>>>>>>
>>>>>> I wouldn't get into this debate were it not for the fact that the
>>>>>> property you have created is called "testMode." I would much
>>>>>> rather have it not imply it's only for testing, with a name like
>>>>>> "delayedWrite" or "relaxedDurability" or some such.
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Sunitha Kambhampati wrote:
>>>>>>
>>>>>>> A little background: Sometime earlier on the list, Dan posted a
>>>>>>> fix to make derby go faster with relaxed durability with some
>>>>>>> flags. The post is at
>>>>>>> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>>>>>>
>>>>>>> This mode is very useful for unit testing or at development time
>>>>>>> when recoverability is not required.
>>>>>>> Basically in this mode, syncs are disabled for logs, data writes
>>>>>>> at checkpoint, page allocation when file is grown; - what this
>>>>>>> means is that data is not flushed all the way to the disk and in
>>>>>>> most cases i/o cost is not involved. Note, code already exists
>>>>>>> in Derby to do this.
>>>>>>> So for Derby 218, This patch addresses the following
>>>>>>> requirements: 1) Have a single property to enable this relaxed
>>>>>>> durability mode, so it is easy for users to enable it.
>>>>>>> 2) Print message to derby.log that this mode is enabled
>>>>>>> 3) A way to report boot errors that may be because of this option
>>>>>>> being enabled. What this maps to is - have a marker to recognize
>>>>>>> that database was booted in this mode, and then on subsequent
>>>>>>> boot; if errors happen during recovery - report a message that it
>>>>>>> could have happened because of this mode being set.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>
>>
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Sunitha Kambhampati <ks...@gmail.com>.
I like this name : derby.system.durability=test
I will wait for Suresh's comments and then change the name of the
property after that unless someone else has a better suggestion.
Thanks for your input.
Sunitha.
David Van Couvering wrote:
> I think testMode isn't very clear what it's doing. I agree that
> relaxedDurability is not correct because it doesn't communicate that
> you may not be able to boot the database.
>
> How about derby.system.fast-and-loose :)
>
> Seriously, how about
>
> derby.system.durability=test
>
> (you can't really say "none" because data pages are being written to
> disk)
>
> or derby.system.durability.testMode=true
>
> I personally like derby.system.durability=test, because then later we
> can add derby.system.durability=relaxed for true relaxed durability
> where the database is durable, and derby.system.durability=none for
> when we implement in-memory storage.
>
> David
>
> Sunitha Kambhampati wrote:
>
>> This patch disables syncs for
>> - 1)the log file at each commit
>> - 2)the log file before data page makes it to disk
>> - 3)data page allocation when file is grown
>> - 4)data writes during checkpoint.
>>
>> Thus, when this mode is enabled, syncs are not enforcing proper WAL
>> protocol and might lead to database not being able to boot. Also
>> earlier when I did a search on the web for the term relaxed
>> durability , it seemed to me that the term was used for cases when it
>> is ok to lose committed transactions but the database should be able
>> to boot successfully.
>>
>> So does derby.system.testMode seem ok given that it might not be
>> appropriate in a production like environment...
>>
>> Or, maybe another name -
>>
>> call this mode of no syncs as derby.system.durable=none ( or
>> derby.storage.durable=none).
>> and in the future when someone implements the case that was discussed
>> earlier on list
>> (http://mail-archives.apache.org/mod_mbox/db-derby-dev/200504.mbox/%3c425C6489.4070205@sbcglobal.net%3e
>> ) where only #1 and #3 syncs are disabled, that would ensure that
>> database would boot ok, with losing some committed transactions, this
>> setting could be derby.system.durable=partial or something similar.
>>
>> Any comments.
>>
>> Thanks,
>> Sunitha.
>>
>> David Van Couvering wrote:
>>
>>> After I wrote my email, I wondered if the feature as currently
>>> implemented wasn't quite what I was thinking we should have. I
>>> agree that if you potentially can't boot your database, this is not
>>> a production-level feature.
>>>
>>> I second the motion to see more work done to implement the relaxed
>>> durability option that guarantees a bootable database, that's what I
>>> was thinking of when I sent my previous email.
>>>
>>> Thanks,
>>>
>>> David
>>>
>>> Mike Matrigali wrote:
>>>
>>>> As I have posted before I have concerns about this mode, as it can
>>>> definitely produce a database which can not boot. But the discussions
>>>> here convinced me
>>>> that it was useful for a number of applications, so now believe it
>>>> should be checked in. I definitely have no career path in marketing
>>>> as my first take at a name was corrupt_your_db=true :-) . So testMode
>>>> seemed ok to me, but if another name is better that is fine with me
>>>> also.
>>>>
>>>> Going forward I would like to see more work done to implement the
>>>> relaxed durability option suresh and I were discussing. I believe
>>>> that with some code changes file allocation, log write and many of
>>>> the data write sync's can be eliminated and still guarantee a bootable
>>>> database. This mode would not guarantee a committed transaction,
>>>> but would guarantee that database on a disk with enough free space
>>>> would boot and that the db would represent only complete
>>>> transactions (either fully applied or not). This option would
>>>> be slower than what is available from this patch so I believe both
>>>> features are useful.
>>>>
>>>> David Van Couvering wrote:
>>>>
>>>>> Hi, Sunitha. Thanks for your work on this. My comment is more a
>>>>> "marketing" comment than a technical one. I disagree that this is
>>>>> useful only for testing and development. As I mentioned in
>>>>> previous emails, there are a number of customers who may find this
>>>>> very useful indeed, who are willing to trade off 100% guarantee of
>>>>> all transactions being available on recovery for significant
>>>>> increases in performance.
>>>>>
>>>>> I wouldn't get into this debate were it not for the fact that the
>>>>> property you have created is called "testMode." I would much
>>>>> rather have it not imply it's only for testing, with a name like
>>>>> "delayedWrite" or "relaxedDurability" or some such.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> David
>>>>>
>>>>> Sunitha Kambhampati wrote:
>>>>>
>>>>>> A little background: Sometime earlier on the list, Dan posted a
>>>>>> fix to make derby go faster with relaxed durability with some
>>>>>> flags. The post is at
>>>>>> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>>>>>
>>>>>> This mode is very useful for unit testing or at development time
>>>>>> when recoverability is not required.
>>>>>> Basically in this mode, syncs are disabled for logs, data writes
>>>>>> at checkpoint, page allocation when file is grown; - what this
>>>>>> means is that data is not flushed all the way to the disk and in
>>>>>> most cases i/o cost is not involved. Note, code already exists
>>>>>> in Derby to do this.
>>>>>> So for Derby 218, This patch addresses the following
>>>>>> requirements: 1) Have a single property to enable this relaxed
>>>>>> durability mode, so it is easy for users to enable it.
>>>>>> 2) Print message to derby.log that this mode is enabled
>>>>>> 3) A way to report boot errors that may be because of this option
>>>>>> being enabled. What this maps to is - have a marker to recognize
>>>>>> that database was booted in this mode, and then on subsequent
>>>>>> boot; if errors happen during recovery - report a message that it
>>>>>> could have happened because of this mode being set.
>>>>>
>>>>>
>>>>>
>>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Suresh Thalamati <su...@gmail.com>.
My two cents:
How about cryptic one like
derby.system.durabilityLevel = 0
0 - mean none.
That way some one using it will be forced to read the doc and find
out what it mean :-)
-suresht
Daniel John Debrunner wrote:
>David Van Couvering wrote:
>
>
>
>>I think testMode isn't very clear what it's doing. I agree that
>>relaxedDurability is not correct because it doesn't communicate that you
>>may not be able to boot the database.
>>
>>How about derby.system.fast-and-loose :)
>>
>>Seriously, how about
>>
>>derby.system.durability=test
>>
>>(you can't really say "none" because data pages are being written to disk)
>>
>>
>
>but they are not guaranteed to be written to disk, that's what I meant
>by 'none' originally. I personally think 'test' describes how it might
>be used and doesn't describe the durability, which is what the value of
>such a property should be doing.
>
>However 'Test' is probably fine, another term could be added if someone
>comes up with a better description, so that something like these two
>options would mean the same thing
>
>derby.system.durability=test
>derby.system.durability=all_bets_are_off
>
>Dan.
>
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Daniel John Debrunner <dj...@debrunners.com>.
David Van Couvering wrote:
> I think testMode isn't very clear what it's doing. I agree that
> relaxedDurability is not correct because it doesn't communicate that you
> may not be able to boot the database.
>
> How about derby.system.fast-and-loose :)
>
> Seriously, how about
>
> derby.system.durability=test
>
> (you can't really say "none" because data pages are being written to disk)
but they are not guaranteed to be written to disk, that's what I meant
by 'none' originally. I personally think 'test' describes how it might
be used and doesn't describe the durability, which is what the value of
such a property should be doing.
However 'Test' is probably fine, another term could be added if someone
comes up with a better description, so that something like these two
options would mean the same thing
derby.system.durability=test
derby.system.durability=all_bets_are_off
Dan.
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by David Van Couvering <Da...@Sun.COM>.
I think testMode isn't very clear what it's doing. I agree that
relaxedDurability is not correct because it doesn't communicate that you
may not be able to boot the database.
How about derby.system.fast-and-loose :)
Seriously, how about
derby.system.durability=test
(you can't really say "none" because data pages are being written to disk)
or derby.system.durability.testMode=true
I personally like derby.system.durability=test, because then later we
can add derby.system.durability=relaxed for true relaxed durability
where the database is durable, and derby.system.durability=none for when
we implement in-memory storage.
David
Sunitha Kambhampati wrote:
> This patch disables syncs for
> - 1)the log file at each commit
> - 2)the log file before data page makes it to disk
> - 3)data page allocation when file is grown
> - 4)data writes during checkpoint.
>
> Thus, when this mode is enabled, syncs are not enforcing proper WAL
> protocol and might lead to database not being able to boot.
> Also earlier when I did a search on the web for the term relaxed
> durability , it seemed to me that the term was used for cases when it is
> ok to lose committed transactions but the database should be able to
> boot successfully.
>
> So does derby.system.testMode seem ok given that it might not be
> appropriate in a production like environment...
>
> Or, maybe another name -
>
> call this mode of no syncs as derby.system.durable=none ( or
> derby.storage.durable=none).
> and in the future when someone implements the case that was discussed
> earlier on list
> (http://mail-archives.apache.org/mod_mbox/db-derby-dev/200504.mbox/%3c425C6489.4070205@sbcglobal.net%3e
> ) where only #1 and #3 syncs are disabled, that would ensure that
> database would boot ok, with losing some committed transactions, this
> setting could be derby.system.durable=partial or something similar.
>
> Any comments.
>
> Thanks,
> Sunitha.
>
> David Van Couvering wrote:
>
>> After I wrote my email, I wondered if the feature as currently
>> implemented wasn't quite what I was thinking we should have. I agree
>> that if you potentially can't boot your database, this is not a
>> production-level feature.
>>
>> I second the motion to see more work done to implement the relaxed
>> durability option that guarantees a bootable database, that's what I
>> was thinking of when I sent my previous email.
>>
>> Thanks,
>>
>> David
>>
>> Mike Matrigali wrote:
>>
>>> As I have posted before I have concerns about this mode, as it can
>>> definitely produce a database which can not boot. But the discussions
>>> here convinced me
>>> that it was useful for a number of applications, so now believe it
>>> should be checked in. I definitely have no career path in marketing
>>> as my first take at a name was corrupt_your_db=true :-) . So testMode
>>> seemed ok to me, but if another name is better that is fine with me
>>> also.
>>>
>>> Going forward I would like to see more work done to implement the
>>> relaxed durability option suresh and I were discussing. I believe
>>> that with some code changes file allocation, log write and many of
>>> the data write sync's can be eliminated and still guarantee a bootable
>>> database. This mode would not guarantee a committed transaction,
>>> but would guarantee that database on a disk with enough free space
>>> would boot and that the db would represent only complete transactions
>>> (either fully applied or not). This option would
>>> be slower than what is available from this patch so I believe both
>>> features are useful.
>>>
>>> David Van Couvering wrote:
>>>
>>>> Hi, Sunitha. Thanks for your work on this. My comment is more a
>>>> "marketing" comment than a technical one. I disagree that this is
>>>> useful only for testing and development. As I mentioned in previous
>>>> emails, there are a number of customers who may find this very
>>>> useful indeed, who are willing to trade off 100% guarantee of all
>>>> transactions being available on recovery for significant increases
>>>> in performance.
>>>>
>>>> I wouldn't get into this debate were it not for the fact that the
>>>> property you have created is called "testMode." I would much rather
>>>> have it not imply it's only for testing, with a name like
>>>> "delayedWrite" or "relaxedDurability" or some such.
>>>>
>>>> Thanks,
>>>>
>>>> David
>>>>
>>>> Sunitha Kambhampati wrote:
>>>>
>>>>> A little background: Sometime earlier on the list, Dan posted a fix
>>>>> to make derby go faster with relaxed durability with some flags.
>>>>> The post is at
>>>>> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>>>>
>>>>> This mode is very useful for unit testing or at development time
>>>>> when recoverability is not required.
>>>>> Basically in this mode, syncs are disabled for logs, data writes at
>>>>> checkpoint, page allocation when file is grown; - what this means
>>>>> is that data is not flushed all the way to the disk and in most
>>>>> cases i/o cost is not involved. Note, code already exists in Derby
>>>>> to do this.
>>>>> So for Derby 218, This patch addresses the following
>>>>> requirements: 1) Have a single property to enable this relaxed
>>>>> durability mode, so it is easy for users to enable it.
>>>>> 2) Print message to derby.log that this mode is enabled
>>>>> 3) A way to report boot errors that may be because of this option
>>>>> being enabled. What this maps to is - have a marker to recognize
>>>>> that database was booted in this mode, and then on subsequent boot;
>>>>> if errors happen during recovery - report a message that it could
>>>>> have happened because of this mode being set.
>>>>
>>>>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Sunitha Kambhampati <ks...@gmail.com>.
This patch disables syncs for
- 1)the log file at each commit
- 2)the log file before data page makes it to disk
- 3)data page allocation when file is grown
- 4)data writes during checkpoint.
Thus, when this mode is enabled, syncs are not enforcing proper WAL
protocol and might lead to database not being able to boot.
Also earlier when I did a search on the web for the term relaxed
durability , it seemed to me that the term was used for cases when it is
ok to lose committed transactions but the database should be able to
boot successfully.
So does derby.system.testMode seem ok given that it might not be
appropriate in a production like environment...
Or, maybe another name -
call this mode of no syncs as derby.system.durable=none ( or
derby.storage.durable=none).
and in the future when someone implements the case that was discussed
earlier on list
(http://mail-archives.apache.org/mod_mbox/db-derby-dev/200504.mbox/%3c425C6489.4070205@sbcglobal.net%3e
) where only #1 and #3 syncs are disabled, that would ensure that
database would boot ok, with losing some committed transactions, this
setting could be derby.system.durable=partial or something similar.
Any comments.
Thanks,
Sunitha.
David Van Couvering wrote:
> After I wrote my email, I wondered if the feature as currently
> implemented wasn't quite what I was thinking we should have. I agree
> that if you potentially can't boot your database, this is not a
> production-level feature.
>
> I second the motion to see more work done to implement the relaxed
> durability option that guarantees a bootable database, that's what I
> was thinking of when I sent my previous email.
>
> Thanks,
>
> David
>
> Mike Matrigali wrote:
>
>> As I have posted before I have concerns about this mode, as it can
>> definitely produce a database which can not boot. But the discussions
>> here convinced me
>> that it was useful for a number of applications, so now believe it
>> should be checked in. I definitely have no career path in marketing
>> as my first take at a name was corrupt_your_db=true :-) . So testMode
>> seemed ok to me, but if another name is better that is fine with me
>> also.
>>
>> Going forward I would like to see more work done to implement the
>> relaxed durability option suresh and I were discussing. I believe
>> that with some code changes file allocation, log write and many of
>> the data write sync's can be eliminated and still guarantee a bootable
>> database. This mode would not guarantee a committed transaction,
>> but would guarantee that database on a disk with enough free space
>> would boot and that the db would represent only complete transactions
>> (either fully applied or not). This option would
>> be slower than what is available from this patch so I believe both
>> features are useful.
>>
>> David Van Couvering wrote:
>>
>>> Hi, Sunitha. Thanks for your work on this. My comment is more a
>>> "marketing" comment than a technical one. I disagree that this is
>>> useful only for testing and development. As I mentioned in previous
>>> emails, there are a number of customers who may find this very
>>> useful indeed, who are willing to trade off 100% guarantee of all
>>> transactions being available on recovery for significant increases
>>> in performance.
>>>
>>> I wouldn't get into this debate were it not for the fact that the
>>> property you have created is called "testMode." I would much rather
>>> have it not imply it's only for testing, with a name like
>>> "delayedWrite" or "relaxedDurability" or some such.
>>>
>>> Thanks,
>>>
>>> David
>>>
>>> Sunitha Kambhampati wrote:
>>>
>>>> A little background: Sometime earlier on the list, Dan posted a fix
>>>> to make derby go faster with relaxed durability with some flags.
>>>> The post is at
>>>> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>>>
>>>> This mode is very useful for unit testing or at development time
>>>> when recoverability is not required.
>>>> Basically in this mode, syncs are disabled for logs, data writes at
>>>> checkpoint, page allocation when file is grown; - what this means
>>>> is that data is not flushed all the way to the disk and in most
>>>> cases i/o cost is not involved. Note, code already exists in Derby
>>>> to do this.
>>>> So for Derby 218, This patch addresses the following
>>>> requirements: 1) Have a single property to enable this relaxed
>>>> durability mode, so it is easy for users to enable it.
>>>> 2) Print message to derby.log that this mode is enabled
>>>> 3) A way to report boot errors that may be because of this option
>>>> being enabled. What this maps to is - have a marker to recognize
>>>> that database was booted in this mode, and then on subsequent boot;
>>>> if errors happen during recovery - report a message that it could
>>>> have happened because of this mode being set.
>>>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by David Van Couvering <Da...@Sun.COM>.
After I wrote my email, I wondered if the feature as currently
implemented wasn't quite what I was thinking we should have. I agree
that if you potentially can't boot your database, this is not a
production-level feature.
I second the motion to see more work done to implement the relaxed
durability option that guarantees a bootable database, that's what I was
thinking of when I sent my previous email.
Thanks,
David
Mike Matrigali wrote:
> As I have posted before I have concerns about this mode, as it can
> definitely produce a database which can not boot. But the discussions
> here convinced me
> that it was useful for a number of applications, so now believe it
> should be checked in. I definitely have no career path in marketing
> as my first take at a name was corrupt_your_db=true :-) . So testMode
> seemed ok to me, but if another name is better that is fine with me
> also.
>
> Going forward I would like to see more work done to implement the
> relaxed durability option suresh and I were discussing. I believe
> that with some code changes file allocation, log write and many of
> the data write sync's can be eliminated and still guarantee a bootable
> database. This mode would not guarantee a committed transaction,
> but would guarantee that database on a disk with enough free space
> would boot and that the db would represent only complete transactions
> (either fully applied or not). This option would
> be slower than what is available from this patch so I believe both
> features are useful.
>
> David Van Couvering wrote:
>
>> Hi, Sunitha. Thanks for your work on this. My comment is more a
>> "marketing" comment than a technical one. I disagree that this is
>> useful only for testing and development. As I mentioned in previous
>> emails, there are a number of customers who may find this very useful
>> indeed, who are willing to trade off 100% guarantee of all
>> transactions being available on recovery for significant increases in
>> performance.
>>
>> I wouldn't get into this debate were it not for the fact that the
>> property you have created is called "testMode." I would much rather
>> have it not imply it's only for testing, with a name like
>> "delayedWrite" or "relaxedDurability" or some such.
>>
>> Thanks,
>>
>> David
>>
>> Sunitha Kambhampati wrote:
>>
>>> A little background: Sometime earlier on the list, Dan posted a fix
>>> to make derby go faster with relaxed durability with some flags. The
>>> post is at
>>> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>>
>>> This mode is very useful for unit testing or at development time when
>>> recoverability is not required.
>>> Basically in this mode, syncs are disabled for logs, data writes at
>>> checkpoint, page allocation when file is grown; - what this means is
>>> that data is not flushed all the way to the disk and in most cases
>>> i/o cost is not involved. Note, code already exists in Derby to do
>>> this.
>>> So for Derby 218, This patch addresses the following requirements:
>>> 1) Have a single property to enable this relaxed durability mode, so
>>> it is easy for users to enable it.
>>> 2) Print message to derby.log that this mode is enabled
>>> 3) A way to report boot errors that may be because of this option
>>> being enabled. What this maps to is - have a marker to recognize that
>>> database was booted in this mode, and then on subsequent boot; if
>>> errors happen during recovery - report a message that it could have
>>> happened because of this mode being set.
>>>
>>> Changes are not much. svn stat
>>> M java\engine\org\apache\derby\impl\store\raw\log\LogToFile.java
>>> M
>>> java\engine\org\apache\derby\impl\store\raw\data\BaseDataFileFactory.java
>>>
>>> M
>>> java\engine\org\apache\derby\impl\store\raw\data\RAFContainer.java
>>> M java\engine\org\apache\derby\iapi\reference\MessageId.java
>>> M java\engine\org\apache\derby\iapi\reference\Property.java
>>> M java\engine\org\apache\derby\loc\messages_en.properties
>>> A
>>> java\testing\org\apache\derbyTesting\functionTests\tests\store\TestNoSyncMode.java
>>>
>>> M
>>> java\testing\org\apache\derbyTesting\functionTests\tests\store\copyfiles.ant
>>>
>>> A
>>> java\testing\org\apache\derbyTesting\functionTests\tests\store\TestNoSyncMode_derby.properties
>>>
>>> A
>>> java\testing\org\apache\derbyTesting\functionTests\master\TestNoSyncMode.out
>>>
>>> M
>>> java\testing\org\apache\derbyTesting\functionTests\suites\storemats.runall
>>>
>>>
>>> Since this is a longish email , for those who may not read the rest
>>> of it, here are the testing results
>>>
>>> Testing results:
>>> - I ran derbyall with 1.4.2 jvm and all tests passed. - I ran the
>>> storeall suite separately both with setting the
>>> derby.system.testMode property to true and without it. with this
>>> property set, the storeall suite ran about 2 times as fast.
>>> -------------------------------
>>>
>>> Below I explain how the patch addresses the above requirements and
>>> try to provide details on how I went about making those changes
>>>
>>> 0) Note
>>> 1) A single property has been added to enable this relaxed durability
>>> option. The property name is derby.system.testMode and takes in
>>> value true or false. By default it is false. It can be set as a
>>> command line option to the JVM when starting the application or
>>> within the application or in the derby.properites file. Property is
>>> loaded at boot time, so for it to have an effect you need to enable
>>> it at boot time. More comments added in code itself. see variable
>>> TESTMODE_NO_SYNC = "derby.system.testMode"; in Property.java.
>>>
>>> (In this patch, I have used 'no_sync' as suffix in variable names
>>> because I think with respect to store - that is what this mode is all
>>> about - disabling syncs for the cases already mentioned earlier in
>>> this mail)
>>>
>>> I chose the property name derby.system.testMode for this
>>> - represents a higher concept as to when one would use relaxed
>>> durability (no sync) option.
>>> - mostly it should be enabled only when data is not important and
>>> ideally maybe for testing and development purposes,
>>> - also with the hope that the word 'testMode' would prompt users to
>>> look this property up before using it in a production like
>>> environment where it may not necessarily be appropriate.
>>>
>>> Code changes for this:
>>> - Added this new property derby.system.testMode in
>>> java\engine\org\apache\derby\iapi\reference\Property.java
>>>
>>> - Removed the following properties from Property.java as they are no
>>> longer required.
>>> derby.storage.dataNotSyncedAtCheckPoint=true ( I'll refer to
>>> this as DNSAC in notes below)
>>> derby.storage.dataNotSyncedAtAllocation=true ( I'll refer to
>>> this as DNSAA in notes below)
>>> derby.storage.logNotSynced=true (I'll refer to this as
>>> LNS in notes below)
>>>
>>> - Previously code existed for enabling the DNSAC, DNSAA and LNS
>>> options conditional on Performance.MEASURE
>>>
>>> So how it works is , the 2 variables in BaseDataFileFactory.java are
>>> used to control if syncs happen or not for data pages at allocation
>>> and at checkpoint.
>>> dataNotSyncedAtAllocation dataNotSyncedAtCheckpoint
>>>
>>> And in java/engine/org/apache/derby/impl/store/raw/log/LogToFile,
>>> the logNotSynced variable is used to control if syncs happen for the
>>> logs are not.
>>>
>>> These variables are enabled (set to true) if Performance.MEASURE is
>>> set to true, and if the DNSAC, and DSNAA propertie are enabled.
>>>
>>> So all that is required now is
>>> - remove conditional on Performance.MEASURE in these cases, instead
>>> use the derby.system.testMode property to enable them . This happens
>>> in the boot methods
>>> - make sure to remove any conditionals on Performance.MEASURE that is
>>> used to disable syncs but instead control it by the variables
>>> mentioned above.. ie e.g. dataNotSyncedAtAllocation in
>>> BaseDataFileFactory.java ...
>>> - remove reading of the DNSAC, DNSAA,LNS property as they are not
>>> needed anymore
>>>
>>> Changes were needed to following files - i)
>>> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
>>> (check boot method)
>>> ii) java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
>>> iii) java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>>> (check boot method).
>>>
>>> 2) Write to the derby.log a warning message
>>>
>>> Needed to add a new message.
>>> Messages need to be translated, so I made the following changes
>>>
>>> i) added a variable in
>>> java/engine/org/apache/derby/iapi/reference/MessageId.java to
>>> represent this new message.
>>> String STORE_TESTMODE_NO_SYNC = "D013";
>>>
>>> ii) Message content added to
>>> java/engine/org/apache/derby/loc/messages_en.properties
>>> D013=WARNING: {0} is set to true. In this mode, there is no guarantee
>>> that the system will recover a system crash or JVM termination.
>>> Enable this property only when there is no need for recoverability \n
>>>
>>> iii) In the boot process, rawstore boot calls logfactory boot, so the
>>> first time the derby.system.testMode property is read, it is in
>>> rawstore, so added code to print the warning message in
>>> BaseDataFileFactory.boot(..)
>>>
>>>
>>> 3) A way to report boot errors that may be because of this option
>>> being enabled. What this maps to is - have a marker to recognize that
>>> database was booted in this mode, and then on subsequent boot if
>>> errors happen during recovery report a message that it could have
>>> happened because of this mode being set.
>>>
>>> - To write a marker out , log.ctrl file is used, it has a few spare
>>> bytes so no major changes needed here. ( ie no disk format changes.... )
>>> Check the method readControlFile in
>>> java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>>>
>>> - Used the first spare byte available in log control file which will
>>> be used to store information about if derby.system.testMode is set or
>>> not.
>>> Added variable TESTMODE_NO_SYNC_FLAG_OFFSET to represent this offset
>>> in LogToFile.java
>>>
>>> - The value written out if this property is enabled is
>>> TESTMODE_NO_SYNC_TRUE = 0x1 else a 0 is written out. ( I didnt like
>>> to put the 0 but wasnt feeling too strong to adding a new static byte
>>> variable either.. and as rest of the code around it in
>>> writeControlFile seems to use 0 as is , I just followed the same
>>> approach).
>>>
>>> - Change made to readControlFile to read in the value for the
>>> testmode case when Logfactory is booted, the flag is read and value
>>> stored
>>> in variable called wasDBInTestModeNoSync. This variable keeps track
>>> of if database was previously booted in the derby.system.testMode or
>>> not. Comes in use for error reporting.
>>>
>>> - Also added a message to report to the derby.log incase database was
>>> previously booted with derby.system.testMode set to true. Change to
>>> messages_en.properties and MessageId.java.
>>> L020=WARNING: The database was previously booted with {0} set to
>>> true. Note that this mode {0}=true does not guarantee recoverability \n
>>>
>>> little on the flow with respect to writeControlFile .. if you look at
>>> the code in LogToFile for boot and recover, writeControlFile is
>>> called a couple of times.. to read the checkpoint instant etc..
>>> - For my changes, I am just copy/paste the comments from
>>> writeControlFile(...) , Note case4 below .. which is the interesting
>>> one.
>>>
>>> // A spare byte at offset TESTMODE_NO_SYNC_FLAG_OFFSET
>>> // is used to write out if database was in
>>> derby.system.testMode=true mode
>>> // or not.
>>> // This byte will have one of the two values
>>> // - TESTMODE_NO_SYNC_TRUE to represent database was booted
>>> // in this mode
>>> // - 0 to represent database was not booted in this mode
>>> // // The sole purpose of this flag in control file is
>>> to help
>>> // identify any recovery problems that might happen as a
>>> result of this
>>> // mode being set.
>>> //
>>> // Possible scenarios. In table below, cases are listed giving
>>> // the value of derby.system.testMode if it was enabled or not
>>> at boot time
>>> //
>>> ---------------------------------------------------------------
>>> // Case Previous Current Action , what should
>>> the flag be set to in log.ctrl
>>> // Boot Boot file
>>> // --------------------------------------------------------------
>>> // 1 - true write
>>> TESTMODE_NO_SYNC_TRUE
>>> // 2 - false write 0
>>> // 3 false false write 0
>>> // 4 true false write
>>> TESTMODE_NO_SYNC_TRUE
>>> // 5 true true write
>>> TESTMODE_NO_SYNC_TRUE
>>> //
>>> // Case 4 is the interesting case here.
>>> // one cannot write out the derby.system.testMode is disabled
>>> just yet
>>> // because it is possible that the database recovery might
>>> fail and on subsequent
>>> // restarts this state would be lost. So only when recovery is
>>> successful, will
>>> // we update the flag in the log control file to indicate that
>>> the derby.system.testMode
>>> // is not enabled. (This will happen at the end of recovery ,
>>> see recover method)
>>> //
>>> // Case 1, 2 is when database is created fresh with this
>>> property enabled.
>>> //
>>> // wasDBInTestModeNoSync has information if database was
>>> previously booted
>>> // in derby.system.testMode=true mode
>>>
>>> To handle case 4, changes went into recover () method , if database
>>> recovery is successful only then we update the flag in the control
>>> file to say database is not booted with this property enabled. Since
>>> there was no method available to update the log control file, added a
>>> new method updateTestModeFlagInCtrlFile(byte value) to do that.
>>>
>>> So now that changes are done to write the marker to the control file
>>> and to read it, it is necessary to take care of case when error happens.
>>>
>>> - added a new message to report that cause of an error could be
>>> related to this property being set
>>> added a new variable in MessageId.LOG_TESTMODE_NO_SYNC_ERR in
>>> java/engine/org/apache/derby/iapi/reference/MessageId.java
>>> and the message to
>>> java/engine/org/apache/derby/loc/messages_en.properties
>>> L021=WARNING: The database was either previously booted or is
>>> currently booted with {0} set to true. Note that this mode {0}=true
>>> does not guarantee recoverability, and is probably what might have
>>> caused this boot error \n
>>> - added MessageId.LOG_TESTMODE_NO_SYNC_ERR in
>>> java/engine/org/apache/derby/iapi/reference/MessageId.java
>>>
>>> Added a new method logErrMsgForTestModeNoSync() in LogToFile.java to
>>> print out this message if any error happens when database is in the
>>> influence of this property.
>>>
>>> In deciding what the best place would be to call the
>>> logErrMsgForTestModeNoSync, I debated between adding it in
>>> markCorrupt() versus logErrMsg(..). It seemed like if error happened
>>> during boot - the flow was to call markCorrupt which would call
>>> logErrMsg. Some error messages seem to call logErrMsg(..)
>>> directly. So I picked the logErrMsg as it covered most of the
>>> errors thrown during boot/recovery that would be related to something
>>> with this property being set.
>>> -------------------------------------------
>>>
>>> TESTING
>>>
>>> 1) I added one new java file per the derby test harness, to test
>>> the following
>>> - check if the property is enabled correctly by timing some inserts
>>> into a table.
>>> - check if the correct flag (TESTMODE_NO_SYNC_TRUE) is written out
>>> into the log.ctrl file
>>> - check if the derby.log has the warning message.
>>>
>>> Changes include
>>> i)Added new test to
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>>>
>>> ii)Added
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>>>
>>>
>>> TestNoSyncMode_derby.properties has
>>> derby.system.testMode=true
>>>
>>> This property file is needed so when test is run it picks up this
>>> property.
>>>
>>> iii)The TestNoSyncMode_derby.properties is added to copyfiles.ant so
>>> it will be copied over when compiling derby tests.
>>>
>>> iv) To enable this new test as part of the store suite, I modified the
>>> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
>>>
>>> added store/TestNoSyncMode.java
>>>
>>> v) To get my correct output file, first i just put an initial empty
>>> file in
>>> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>>>
>>>
>>> Ran the test after compiling source; java
>>> org.apache.derbyTesting.functionTests.harness.RunTest
>>> store/TestNoSyncMode.java
>>> Then I updated the out file in the master directory, after checking
>>> if the TestNoSyncMode.out file was correct.
>>>
>>> 2) For the error messages on a boot error, it is difficult to put it
>>> in a test, so I checked this in the debugger and it works ok.
>>>
>>> Meanwhile, Suresh Thalamati posted on the list that he is working on
>>> a corruptible storage factory, once that is there - I am hoping I
>>> could use that to have a test to check the error messages for boot
>>> errors.
>>>
>>> As far as I can tell, this does not affect upgrade and such since we
>>> are not changing the disk format etc.. ..There is one spare byte in
>>> log.ctrl file that is being used now as a result of this change and
>>> this byte value should not have been used to represent anything
>>> useful by any earlier version
>>>
>>> Testing results (already mentioned in the beginning of this email).
>>>
>>> Please give your comments. Thanks,
>>> Sunitha.
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> Index: java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>>> ===================================================================
>>> --- java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>>> (revision 165265)
>>> +++ java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>>> (working copy)
>>> @@ -265,7 +265,38 @@
>>>
>>> /* Log Control file flags. */
>>> private static final byte IS_BETA_FLAG = 0x1;
>>> -
>>> + + /**
>>> + * When the derby.system.testMode property is enabled, the store
>>> + * system will not force sync calls in the following cases
>>> + * - for the log file at each commit
>>> + * - for the log file before data page is forced to disk
>>> + * - for page allocation when file is grown
>>> + * - for data writes during checkpoint
>>> + * This means the recovery system may not work properly
>>> + * In order that we recognize this case that the database was
>>> previously
>>> + * booted in this mode, this value is written out
>>> + * into the log control file. This will help prevent us from
>>> + * wasting time to resolve issues in such cases. + * @see
>>> org.apache.derby.iapi.reference.Property#TESTMODE_NO_SYNC
>>> + */
>>> + private static final byte TESTMODE_NO_SYNC_TRUE = 0x1;
>>> + + /**
>>> + * A byte in the log control file is used to store information
>>> + * about if the database is booted in derby.system.testMode mode
>>> + * The first available spare byte that is available for this
>>> purpose is + * after 5 ints ( 4bytes each), a long ( 8 bytes) and
>>> 1 byte in the log control
>>> + * file. Hence the offset is calculated as follows
>>> + */
>>> + private static final int TESTMODE_NO_SYNC_FLAG_OFFSET = 5*4 + 8
>>> + 1;
>>> + + /**
>>> + * keeps track of if the database was booted previously with
>>> + * derby.system.testMode=true + */
>>> + private static boolean wasDBInTestModeNoSync = false;
>>> + /* to err on the conservative side, unless otherwise set,
>>> assume log
>>> * archive is ON */
>>> @@ -362,7 +393,7 @@
>>> // log goes to the log subdirectory underneath the data directory
>>> String logDevice;
>>>
>>> - // debug only flag - disable syncing of log file for debugging
>>> performance.
>>> + // disable syncing of log file when running in
>>> derby.system.testMode enabled
>>> private boolean logNotSynced = false;
>>>
>>> private boolean logArchived = false;
>>> @@ -403,6 +434,7 @@
>>> private CRC32 checksum = new CRC32(); // holder for the
>>> checksum
>>>
>>> + protected static int CHECKSUM_SIZE = 8; // checksum size in bytes
>>>
>>> /**
>>> @@ -1194,8 +1226,28 @@
>>> tf.resetTranId();
>>> }
>>>
>>> - // done with recovery
>>> -
>>> + // If we have reached here successfully, that means recovery
>>> + // was successful
>>> + + // Now that database has recovered successfully and
>>> if it
>>> + // is booted with derby.system.testMode=false mode, there is no
>>> + // need to store information that database was booted
>>> previously in + // derby.system.testMode=true mode. +
>>> // It is safe to update the marker in log.ctrl file to say
>>> + // that the derby.system.testMode in not being used
>>> + + // Need to write to the log.ctrl file as well as the log
>>> mirror file
>>> + if( wasDBInTestModeNoSync && !logNotSynced )
>>> + {
>>> + // write to log control file and the mirror file that the
>>> testmode + // is not used now
>>> + if(!updateTestModeFlagInCtrlFile((byte)0))
>>> + throw StandardException.newException(
>>> + SQLState.LOG_CONTROL_FILE, getControlFileName());
>>> + + wasDBInTestModeNoSync = false;
>>> + } +
>>> /////////////////////////////////////////////////////////////
>>> // setup checktpoint daemon
>>> /////////////////////////////////////////////////////////////
>>> @@ -1207,6 +1259,99 @@
>>> }
>>> }
>>>
>>> + /**
>>> + * Update the flag that represents whether + *
>>> derby.system.testMode is enabled or not in both the log control file
>>> + * as well as the mirror control file
>>> + * <BR>
>>> + * Basically, Read the control file, + * update the flag to
>>> the new passed in value + * recalculate the checksum and write it
>>> out to the log control file
>>> + * <P> MT- synchronized by caller
>>> + * @param value to set
>>> + * @return false if the update didnt happen successfully, else true
>>> + * @throws IOException
>>> + * @throws StandardException
>>> + * @see #readControlFile
>>> + * @see #writeControlFile(StorageFile, long)
>>> + */
>>> + private boolean updateTestModeFlagInCtrlFile(byte value)
>>> + {
>>> + StorageRandomAccessFile logControlFile = null;
>>> + byte barray[] = null;
>>> + StorageFile ctrlFile = null;
>>> + + try
>>> + {
>>> + ctrlFile = getControlFileName();
>>> + logControlFile = privRandomAccessFile(ctrlFile, "rw");
>>> + if (!privCanWrite(ctrlFile))
>>> + return false;
>>> + + // retrieve all except the checksum bytes
>>> + barray = new byte[(int) logControlFile.length() -
>>> CHECKSUM_SIZE];
>>> + logControlFile.readFully(barray);
>>> + + if (SanityManager.DEBUG)
>>> + {
>>> + if (SanityManager.DEBUG_ON(DBG_FLAG))
>>> + {
>>> + SanityManager.DEBUG(DBG_FLAG,
>>> + "Updating derby.system.testMode marker
>>> written out"+
>>> + "to log control file: prev value = " +
>>> + barray[TESTMODE_NO_SYNC_FLAG_OFFSET] + " to
>>> "+ value); + }
>>> + }
>>> + // update the byte at position that represents whether
>>> + // derby.system.testMode was used
>>> + barray[TESTMODE_NO_SYNC_FLAG_OFFSET] = value;
>>> + + // write back into file the updated value
>>> and also compute + // the newchecksum and write it to file
>>> + logControlFile.seek(0);
>>> + logControlFile.write(barray);
>>> + checksum.reset();
>>> + checksum.update(barray, 0, barray.length);
>>> + logControlFile.writeLong(checksum.getValue());
>>> + syncFile(logControlFile);
>>> + logControlFile.close();
>>> +
>>> + // write the same data to mirror control file
>>> + ctrlFile = getMirrorControlFileName();
>>> + logControlFile =
>>> + privRandomAccessFile(ctrlFile, "rw");
>>> + if (!privCanWrite(ctrlFile))
>>> + return false;
>>> + logControlFile.seek(0);
>>> + logControlFile.write(barray);
>>> + logControlFile.writeLong(checksum.getValue());
>>> + syncFile(logControlFile);
>>> + }
>>> + catch(IOException ioe)
>>> + {
>>> + logControlFile = null;
>>> + return false;
>>> + }
>>> + catch(StandardException se)
>>> + {
>>> + logControlFile = null;
>>> + return false;
>>> + }
>>> + finally
>>> + {
>>> + try
>>> + { + if (logControlFile != null)
>>> + logControlFile.close();
>>> + }
>>> + catch(IOException ioe2)
>>> + {
>>> + logControlFile = null;
>>> + return false;
>>> + }
>>> + }
>>> + return true;
>>> + }
>>> /**
>>> Checkpoint the rawStore.
>>>
>>> @@ -2142,10 +2287,61 @@
>>>
>>> //
>>> // write some spare bytes after 2.0 we have 3 + 2(8) spare
>>> bytes.
>>> + // now with v10.1.0.0 we have 2 +2(8) spare bytes as one of
>>> the spare
>>> + // byte is used as a marker to write out if system is runinng
>>> + // in derby.system.testMode=true or not.
>>> + long spare = 0;
>>> + + // A spare byte at offset TESTMODE_NO_SYNC_FLAG_OFFSET
>>> + // is used to write out if database was in
>>> derby.system.testMode=true mode
>>> + // or not. + // This byte will have one of the two
>>> values
>>> + // - TESTMODE_NO_SYNC_TRUE to represent database was booted
>>> + // in this mode + // - 0 to represent database was
>>> not booted in this mode
>>> + // + // The sole purpose of this flag in control
>>> file is to help
>>> + // identify any recovery problems that might happen as a
>>> result of this
>>> + // mode being set. + // + // Possible
>>> scenarios. In table below, cases are listed giving + // the
>>> value of derby.system.testMode if it was enabled or not at boot time
>>> + //
>>> ---------------------------------------------------------------
>>> + // Case Previous Current Action , what should the
>>> flag be set to in log.ctrl + // Boot Boot
>>> file
>>> + //
>>> --------------------------------------------------------------
>>> + // 1 - true write
>>> TESTMODE_NO_SYNC_TRUE + // 2 - false
>>> write 0 + // 3 false false write 0
>>> + // 4 true false write
>>> TESTMODE_NO_SYNC_TRUE + // 5 true true
>>> write TESTMODE_NO_SYNC_TRUE
>>> + // + // Case 4 is the interesting case here.
>>> + // one cannot write out the derby.system.testMode is
>>> disabled just yet
>>> + // because it is possible that the database recovery might
>>> fail and on subsequent
>>> + // restarts this state would be lost. So only when recovery
>>> is successful, will + // we update the flag in the log control
>>> file to indicate that the derby.system.testMode
>>> + // is not enabled. (This will happen at the end of recovery
>>> , see recover method) + // + // Case 1, 2 is when
>>> database is created fresh with this property enabled.
>>> + // + // wasDBInTestModeNoSync has information if
>>> database was previously booted
>>> + // in derby.system.testMode=true mode
>>> + if( !wasDBInTestModeNoSync ) // derby.system.testMode=false
>>> + {
>>> + // in this case, no need to write out any special marker
>>> + // for derby.system.testMode=false case.
>>> + if(!logNotSynced)
>>> + daos.writeByte(0); + else
>>> + daos.writeByte(TESTMODE_NO_SYNC_TRUE); + }
>>> + else
>>> + daos.writeByte(TESTMODE_NO_SYNC_TRUE);
>>> + daos.writeByte(0);
>>> daos.writeByte(0);
>>> - daos.writeByte(0);
>>> daos.writeLong(spare);
>>> daos.flush();
>>> // write the checksum for the control data written
>>> @@ -2281,7 +2477,24 @@
>>> onDiskMinorVersion = dais.readInt();
>>> int dbBuildNumber = dais.readInt();
>>> int flags = dais.readByte();
>>> -
>>> + + // check if the database was running
>>> previously with
>>> + // derby.system.testMode=true mode
>>> + // if database was running previously in
>>> derby.system.testMode=true
>>> + // and if on a restart - recovery fails we want to
>>> be able
>>> + // to report that the boot error could have happened
>>> + // because of this property
>>> + wasDBInTestModeNoSync =(dais.readByte() &
>>> TESTMODE_NO_SYNC_TRUE) != 0;
>>> + + if (SanityManager.DEBUG)
>>> + {
>>> + if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
>>> + SanityManager.DEBUG(LogToFile.DBG_FLAG,
>>> + "log control file, was
>>> derby.system.testMode enabled = " + +
>>> wasDBInTestModeNoSync);
>>> + }
>>> + + onDiskBeta =
>>> (flags & IS_BETA_FLAG) != 0;
>>>
>>> if (onDiskBeta)
>>> @@ -2794,19 +3007,15 @@
>>> isWriteSynced = false;
>>> }
>>>
>>> - if (Performance.MEASURE)
>>> + // if system is running with derby.system.testMode enabled
>>> + // log records and log file are not synced, so
>>> + // set flag to disable log syncs
>>> + if (PropertyUtil.getSystemBoolean(Property.TESTMODE_NO_SYNC))
>>> {
>>> - // debug only flag - disable syncing of log.
>>> - logNotSynced = -
>>> PropertyUtil.getSystemBoolean(Property.STORAGE_LOG_NOT_SYNCED);
>>> -
>>> - if (logNotSynced)
>>> - {
>>> - Monitor.logMessage("logNotSynced = true");
>>> - //if log is Not being synced;files should not be
>>> open in write sync mode
>>> - isWriteSynced = false;
>>> - }
>>> - + // disable syncing of log.
>>> + logNotSynced = true;
>>> + //if log is Not being synced;files should not be open
>>> in write sync mode
>>> + isWriteSynced = false; }
>>>
>>> // try to access the log
>>> @@ -2830,6 +3039,18 @@
>>> if (privExists(logControlFileName))
>>> {
>>> checkpointInstant =
>>> readControlFile(logControlFileName, startParams);
>>> + // in case system was running previously with
>>> derby.system.testMode=true
>>> + // then print a message to the derby log
>>> + if(wasDBInTestModeNoSync)
>>> + {
>>> + // print message stating that the database was
>>> + // previously running with derby.system.testMode=true
>>> + // mode
>>> + Monitor.logMessage(MessageService.getTextMessage(
>>> + MessageId.LOG_WAS_IN_TESTMODE_NO_SYNC,
>>> + Property.TESTMODE_NO_SYNC));
>>> + }
>>> + if (checkpointInstant ==
>>> LogCounter.INVALID_LOG_INSTANT &&
>>>
>>> getMirrorControlFileName().exists())
>>> checkpointInstant =
>>> @@ -2879,8 +3100,9 @@
>>> // blow away the log file if possible
>>> if (!privDelete(logFile) && logFileNumber == 1)
>>> {
>>> + logErrMsgForTestModeNoSync();
>>> throw StandardException.newException(
>>> - SQLState.LOG_INCOMPATIBLE_FORMAT,
>>> dataDirectory);
>>> +
>>> SQLState.LOG_INCOMPATIBLE_FORMAT,dataDirectory);
>>> }
>>>
>>> // If logFileNumber > 1, we are not going to
>>> write that file just
>>> @@ -2913,6 +3135,7 @@
>>>
>>> if (!privDelete(logFile))
>>> {
>>> + logErrMsgForTestModeNoSync();
>>> throw StandardException.newException(
>>> SQLState.LOG_INCOMPATIBLE_FORMAT,
>>> dataDirectory);
>>> @@ -3584,15 +3807,8 @@
>>> }
>>> else
>>> {
>>> - if (Performance.MEASURE)
>>> - {
>>> - if (!logNotSynced)
>>> - logOut.syncLogAccessFile();
>>> - }
>>> - else
>>> - {
>>> - logOut.syncLogAccessFile();
>>> - }
>>> + if (!logNotSynced)
>>> + logOut.syncLogAccessFile();
>>> }
>>>
>>> syncSuceed = true;
>>> @@ -3925,6 +4141,7 @@
>>> */
>>> protected void logErrMsg(String msg)
>>> {
>>> + logErrMsgForTestModeNoSync();
>>> Monitor.logTextMessage(MessageId.LOG_BEGIN_ERROR);
>>> Monitor.logMessage(msg);
>>> Monitor.logTextMessage(MessageId.LOG_END_ERROR);
>>> @@ -3936,6 +4153,7 @@
>>> */
>>> protected void logErrMsg(Throwable t)
>>> {
>>> + logErrMsgForTestModeNoSync();
>>> if (corrupt != null)
>>> {
>>> Monitor.logTextMessage(MessageId.LOG_BEGIN_CORRUPT_STACK);
>>> @@ -3951,6 +4169,22 @@
>>> }
>>> }
>>>
>>> + /**
>>> + * In case of boot errors, and if database is either booted
>>> + * with derby.system.testMode being set or was previously booted
>>> in this
>>> + * mode, mention in the error message that the error is probably
>>> + * because the derby.system.testMode was set. + * Dont want
>>> to waste time to resolve issues in such
>>> + * cases
>>> + * <p>
>>> + * MT - not needed, informational only
>>> + */
>>> + protected void logErrMsgForTestModeNoSync()
>>> + {
>>> + if(logNotSynced || wasDBInTestModeNoSync)
>>> + Monitor.logTextMessage(MessageId.LOG_TESTMODE_NO_SYNC_ERR);
>>> + }
>>> +
>>> private void printErrorStack(Throwable t)
>>> {
>>> Monitor.logMessage("-------------------------\n");
>>> Index:
>>> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
>>>
>>> ===================================================================
>>> ---
>>> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
>>> (revision 165265)
>>> +++
>>> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
>>> (working copy)
>>> @@ -179,11 +179,11 @@
>>> private static final String LINE =
>>> "----------------------------------------------------------------";
>>>
>>> - // debug only flag - disable syncing of data during page
>>> allocation.
>>> - boolean dataNotSyncedAtAllocation;
>>> + // disable syncing of data during page allocation.
>>> + boolean dataNotSyncedAtAllocation = false;
>>>
>>> - // debug only flag - disable syncing of data during checkpoint.
>>> - boolean dataNotSyncedAtCheckpoint;
>>> + // disable syncing of data during checkpoint.
>>> + boolean dataNotSyncedAtCheckpoint = false;
>>>
>>> // these fields can be accessed directly by subclasses if it
>>> needs a
>>> // different set of actions
>>> @@ -375,29 +375,24 @@
>>>
>>> droppedTableStubInfo = new Hashtable();
>>>
>>> - if (Performance.MEASURE)
>>> + /**
>>> + * If derby.system.testMode=true then set flags to +
>>> * disable sync of data pages at allocation when file is grown,
>>> + * disable sync of data writes during checkpoint
>>> + */
>>> + if (PropertyUtil.getSystemBoolean(Property.TESTMODE_NO_SYNC))
>>> {
>>> - // debug only flag - disable syncing of data during
>>> checkpoint.
>>> - dataNotSyncedAtCheckpoint = -
>>> PropertyUtil.getSystemBoolean(
>>> - Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT);
>>> + // - disable syncing of data during checkpoint.
>>> + dataNotSyncedAtCheckpoint = true;
>>>
>>> - // debug only flag - disable syncing of data during page
>>> allocation.
>>> - dataNotSyncedAtAllocation = -
>>> PropertyUtil.getSystemBoolean(
>>> - Property.STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION);
>>> -
>>> - if (dataNotSyncedAtCheckpoint)
>>> - Monitor.logMessage(
>>> - "Warning: " + -
>>> Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT +
>>> - "set to true.");
>>> -
>>> - if (dataNotSyncedAtAllocation)
>>> - Monitor.logMessage(
>>> - "Warning: " + -
>>> Property.STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION +
>>> - "set to true.");
>>> + // - disable syncing of data during page allocation.
>>> + dataNotSyncedAtAllocation = true;
>>> + + // log message stating that
>>> derby.system.testMode
>>> + // has been enabled. +
>>> Monitor.logMessage(MessageService.getTextMessage(
>>> + MessageId.STORE_TESTMODE_NO_SYNC,
>>> + Property.TESTMODE_NO_SYNC));
>>> }
>>>
>>> fileHandler = new RFResource( this);
>>> Index:
>>> java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
>>> ===================================================================
>>> ---
>>> java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
>>> (revision 165265)
>>> +++
>>> java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
>>> (working copy)
>>> @@ -325,15 +325,8 @@
>>> dataFactory.writeInProgress();
>>> try
>>> {
>>> - if (Performance.MEASURE)
>>> - {
>>> - if (!dataFactory.dataNotSyncedAtAllocation)
>>> - fileData.sync( false);
>>> - }
>>> - else
>>> - {
>>> + if (!dataFactory.dataNotSyncedAtAllocation)
>>> fileData.sync( false);
>>> - }
>>> }
>>> finally
>>> {
>>> @@ -504,16 +497,9 @@
>>> dataFactory.writeInProgress();
>>> inwrite = true;
>>>
>>> - if (Performance.MEASURE)
>>> - {
>>> - if (!dataFactory.dataNotSyncedAtAllocation)
>>> - fileData.sync( false);
>>> - }
>>> - else
>>> - {
>>> + if (!dataFactory.dataNotSyncedAtAllocation)
>>> fileData.sync( false);
>>> - }
>>> - }
>>> + }
>>> catch (IOException ioe)
>>> {
>>> // The disk may have run out of space. @@
>>> -629,15 +615,9 @@
>>> dataFactory.writeInProgress();
>>> try
>>> {
>>> - if (Performance.MEASURE)
>>> - {
>>> - if (!dataFactory.dataNotSyncedAtCheckpoint)
>>> - file.sync( false);
>>> - }
>>> - else
>>> - {
>>> - file.sync( false);
>>> - }
>>> + if (!dataFactory.dataNotSyncedAtCheckpoint)
>>> + file.sync( false);
>>> +
>>> }
>>> finally
>>> {
>>> Index: java/engine/org/apache/derby/iapi/reference/MessageId.java
>>> ===================================================================
>>> --- java/engine/org/apache/derby/iapi/reference/MessageId.java
>>> (revision 165265)
>>> +++ java/engine/org/apache/derby/iapi/reference/MessageId.java
>>> (working copy)
>>> @@ -58,8 +58,10 @@
>>> String LOG_CANNOT_CREATE_NEW_DUETO = "L017";
>>> String LOG_MAYBE_INCONSISTENT = "L018";
>>> String LOG_TRANS_LOG_SCAN = "L019";
>>> + String LOG_WAS_IN_TESTMODE_NO_SYNC = "L020"; // system was
>>> running in derby.system.testMode set + String
>>> LOG_TESTMODE_NO_SYNC_ERR = "L021"; // hint that error could
>>> be because + //
>>> derby.system.testMode was set
>>>
>>> -
>>> /*
>>> * Raw Store data
>>> */
>>> @@ -75,6 +77,7 @@
>>> String STORE_BACKUP_ABORTED = "D010";
>>> String STORE_REMOVED_BACKUP = "D011";
>>> String STORE_BACKUP_COMPLETED = "D012";
>>> + String STORE_TESTMODE_NO_SYNC = "D013"; // for
>>> derby.system.testMode is set
>>>
>>>
>>> /*
>>> Index: java/engine/org/apache/derby/iapi/reference/Property.java
>>> ===================================================================
>>> --- java/engine/org/apache/derby/iapi/reference/Property.java
>>> (revision 165265)
>>> +++ java/engine/org/apache/derby/iapi/reference/Property.java
>>> (working copy)
>>> @@ -368,55 +368,47 @@
>>> <P>
>>> */
>>> String STORAGE_TEMP_DIRECTORY = "derby.storage.tempDirectory";
>>> -
>>> + /**
>>> - * derby.storage.dataNotSyncedAtCheckPoint
>>> + * derby.system.testMode
>>> * <p>
>>> - * When set, the store system will not force a sync() call on the
>>> - * containers during a checkpoint.
>>> + * When set, the store system will not force sync calls in the
>>> following
>>> + * cases + * - for the log file at each commit
>>> + * - for the log file before data page is forced to disk
>>> + * - for page allocation when file is grown
>>> + * - for data writes during checkpoint
>>> * <p>
>>> - * An internal debug system only flag. The recovery system will
>>> not
>>> - * work properly if this flag is enabled, it is provided to do
>>> performance
>>> - * debugging to see whether the system is I/O bound based on
>>> checkpoint
>>> - * synchronous I/O.
>>> + * That means, when this property is set to true
>>> + * - a commit no longer guarantees that the transaction's
>>> modification
>>> + * will survive a system crash or JVM termination
>>> + * - the database may not recover successfully upon restart
>>> + * - a near full disk at runtime may cause unexpected errors
>>> * <p>
>>> - *
>>> - **/
>>> - public static final String STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT
>>> = - "derby.storage.dataNotSyncedAtCheckPoint";
>>> -
>>> - /**
>>> - * derby.storage.dataNotSyncedAtAllocation
>>> + * This property is provided for performance reasons and should
>>> ideally
>>> + * only be used when there is no requirement for the database to
>>> recover.
>>> + * <BR> + * One sample use would be to enable this property
>>> when using Derby as a test
>>> + * database, where recoverability is not a concern but
>>> performance is important.
>>> + * <BR>
>>> + * Default value is false
>>> + * <BR>
>>> + * Valid Values
>>> + * Valid values are true or false
>>> + * <BR>
>>> + * Example
>>> + * derby.system.testMode=true
>>> + * One can set this as a command line option to the JVM when
>>> starting the
>>> + * application or in the derby.properties file
>>> + * <BR>
>>> + * This property is static; if you change it while Derby is
>>> running, + * the change does not take effect until you reboot.
>>> * <p>
>>> - * When set, the store system will not force a sync() call on the
>>> - * containers when pages are allocated.
>>> - * <p>
>>> - * An internal debug system only flag. The recovery system will
>>> not
>>> - * work properly if this flag is enabled, it is provided to do
>>> performance
>>> - * debugging to see whether the system is I/O bound based on
>>> page allocation
>>> - * synchronous I/O.
>>> - * <p>
>>> *
>>> **/
>>> - public static final String STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION
>>> = - "derby.storage.dataNotSyncedAtAllocation";
>>> -
>>> - /**
>>> - * derby.storage.logNotSynced
>>> - * <p>
>>> - * When set, the store system will not force a sync() call on
>>> the log at - * commit.
>>> - * <p>
>>> - * An internal debug system only flag. The recovery system will
>>> not
>>> - * work properly if this flag is enabled, it is provided to do
>>> performance
>>> - * debugging to see whether the system is I/O bound based on log
>>> file
>>> - * synchronous I/O.
>>> - * <p>
>>> - *
>>> - **/
>>> - public static final String STORAGE_LOG_NOT_SYNCED = -
>>> "derby.storage.logNotSynced";
>>> -
>>> + public static final String TESTMODE_NO_SYNC = +
>>> "derby.system.testMode";
>>> + /**
>>> * derby.storage.fileSyncTransactionLog
>>> * <p>
>>> Index: java/engine/org/apache/derby/loc/messages_en.properties
>>> ===================================================================
>>> --- java/engine/org/apache/derby/loc/messages_en.properties
>>> (revision 165265)
>>> +++ java/engine/org/apache/derby/loc/messages_en.properties
>>> (working copy)
>>> @@ -1150,7 +1150,10 @@
>>> L016=cannot create a new log file {0}
>>> L017=cannot create a new log file {0} due to {1}
>>> L018=System may be in a inconsistent state, missing file {0}
>>> +L020=WARNING: The database was previously booted with {0} set to
>>> true. Note that this mode {0}=true does not guarantee recoverability \n
>>> +L021=WARNING: The database was either previously booted or is
>>> currently booted with {0} set to true. Note that this mode {0}=true
>>> does not guarantee recoverability, and is probably what might have
>>> caused this boot error \n
>>>
>>> +
>>> # Class Manager
>>> C000=Wrote class {0} to file {1}. Please provide support with the
>>> file and the following exception information: {2}
>>> C001=Class {0} has a unknown certificate type in jar {1}, expecting
>>> X509 certificate.
>>> @@ -1174,6 +1177,7 @@
>>> D010=Backup aborted due to error
>>> D011=removed old backup copy at {0}
>>> D012=Backup completed, log instant at {0} \n
>>> +D013=WARNING: {0} is set to true. In this mode, there is no
>>> guarantee that the system will recover a system crash or JVM
>>> termination. Enable this property only when there is no need for
>>> recoverability \n
>>>
>>> # Connectivity J004=database identity
>>> Index:
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>>>
>>> ===================================================================
>>> ---
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>>> (revision 0)
>>> +++
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>>> (revision 0)
>>> @@ -0,0 +1,202 @@
>>> +/*
>>> + + Derby - Class
>>> org.apache.derbyTesting.functionTests.tests.store.TestNoSyncs
>>> + + Copyright 2002, 2005 The Apache Software Foundation or its
>>> licensors, as applicable.
>>> + + Licensed under the Apache License, Version 2.0 (the "License");
>>> + you may not use this file except in compliance with the License.
>>> + You may obtain a copy of the License at
>>> + + http://www.apache.org/licenses/LICENSE-2.0
>>> + + Unless required by applicable law or agreed to in writing, software
>>> + distributed under the License is distributed on an "AS IS" BASIS,
>>> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>>> implied.
>>> + See the License for the specific language governing permissions and
>>> + limitations under the License.
>>> + + */
>>> +
>>> +package org.apache.derbyTesting.functionTests.tests.store;
>>> +
>>> +import java.sql.Connection;
>>> +import java.sql.Statement;
>>> +import java.sql.PreparedStatement;
>>> +import java.io.*;
>>> +/**
>>> + * This program tests the system when the derby.system.testMode
>>> property is enabled
>>> + *
>>> + * When the derby.system.testMode is set, the system will not do any
>>> sync to the disk and
>>> + * the recovery system will not work property.
>>> + * It is provided for performance reasons and should ideally only be
>>> used
>>> + * when there is no requirement for the database to recover.
>>> + * <p>
>>> + * When set, the system will not do any syncs, the cases namely
>>> + * - no sync of the log file at each commit
>>> + * - no sync of the log file before data page is forced to disk
>>> + * - no sync of page allocation when file is grown
>>> + * - no sync of data writes during checkpoint
>>> + * <p>
>>> + * That means, when this property is set to true,
>>> + * - a commit no longer guarantees that the transaction's modification
>>> + * will survive a system crash or JVM termination
>>> + * - the database may not recover successfully upon restart
>>> + * - a near full disk at runtime may cause unexpected errors
>>> + *
>>> + * This program tests for
>>> + * 1. enabling the derby.system.testMode is actually not doing the
>>> syncs
>>> + * by timing inserts
>>> + * 2. check if a warning message exists in derby.log
>>> + * 3. read log.ctrl file and check if the flag is set or not
>>> + *
>>> + *
>>> + * @author <a href="mailto:ksunithaghm@gmail.com">Sunitha
>>> Kambhampati</a>
>>> + * @version 1.0
>>> + */
>>> +public class TestNoSyncMode
>>> +{
>>> + public static void main(String[] args)
>>> + {
>>> + Connection conn = null;
>>> + Statement s = null;
>>> + PreparedStatement ps = null;
>>> + try
>>> + {
>>> + // use the ij utility to read the property file and
>>> + // make the initial connection.
>>> + org.apache.derby.tools.ij.getPropertyArg(args);
>>> + conn = org.apache.derby.tools.ij.startJBMS();
>>> + + s = conn.createStatement();
>>> + s.execute("create table t1 (c1 int, c2 int)");
>>> + s.close();
>>> + + // Test 1
>>> + // this is a quick check incase someone breaks the
>>> derby.system.testMode + long timeTaken =
>>> doInsertsInAutoCommit(conn);
>>> + conn.close();
>>> + + int approxUpperBound = 3000; // approximate
>>> upper bound in millisecond
>>> + if ( timeTaken > approxUpperBound )
>>> + {
>>> + report("FAIL -- derby.system.testMode mode seems to
>>> be broken.");
>>> + report(" Time to insert rows in test exceeded the
>>> usual limit.");
>>> + }
>>> + + // Test 2
>>> + // Check if derby.log has the warning message
>>> + report("Is warning message about derby.system.testMode
>>> present in derby.log ="+ isMessageInDerbyLog());
>>> + // Test 3
>>> + // Check if marker is correctly written out to
>>> database + markerInControlFile();
>>> + + + }
>>> + catch (Throwable e) {
>>> + report("FAIL -- unexpected exception: "+e);
>>> + e.printStackTrace();
>>> + }
>>> + + }
>>> + + + /**
>>> + * Note doing inserts in autocommit mode is probably the worst
>>> case scenario
>>> + * in terms of performance as each commit will involve a
>>> flush/sync to disk
>>> + * but in case of the derby.system.testMode=true mode, the syncs
>>> dont happen
>>> + * This test case times the inserts and assumes that the inserts
>>> on any system
>>> + * will be less than three second for 500 inserts.
>>> + * Note this upper bound on time is just an approximate
>>> estimation + */
>>> + public static long doInsertsInAutoCommit(Connection conn)
>>> + throws Exception
>>> + {
>>> + PreparedStatement ps = conn.prepareStatement("insert into t1
>>> values(?,?)");
>>> + long count = 0;
>>> + + long start = System.currentTimeMillis();
>>> + + for ( int i = 0; i < 500; i++ )
>>> + {
>>> + ps.setInt(1,i);
>>> + ps.setInt(2,i);
>>> + count += ps.executeUpdate();
>>> + }
>>> + + long end = System.currentTimeMillis();
>>> + report("num successful inserts = "+count);
>>> + + return ( end - start);
>>> + }
>>> + + /**
>>> + * When derby.system.testMode is set, a warning message is
>>> written out to derby.log
>>> + * indicating that the property is set and that it does not
>>> guarantee recoverability
>>> + * This test tests if a message is written out to derby.log or
>>> not + */
>>> + public static boolean isMessageInDerbyLog()
>>> + throws Exception
>>> + {
>>> + BufferedReader reader = null;
>>> + File derbylog = null;
>>> + try
>>> + {
>>> + String derbyHome = System.getProperty("derby.system.home");
>>> + derbylog = new File(derbyHome,"derby.log");
>>> + reader = new BufferedReader(new FileReader(derbylog));
>>> + + String line = null;
>>> + while((line = reader.readLine())!= null)
>>> + {
>>> + if(line.indexOf("derby.system.testMode") != -1)
>>> + return true;
>>> + + }
>>> + return false;
>>> + }
>>> + finally
>>> + {
>>> + if (reader != null)
>>> + {
>>> + reader.close();
>>> + }
>>> + derbylog = null;
>>> + }
>>> + }
>>> +
>>> + /**
>>> + * if derby.system.testMode is set, a marker is written out into
>>> log control file
>>> + * to recognize that the database was previously booted in this
>>> mode + * Test if the marker byte is set correctly or not
>>> + * See comments in org.apache.derby.impl.store.log.LogToFile
>>> for IS_TESTMODE_NO_SYNC_FLAG
>>> + */
>>> + public static void markerInControlFile()
>>> + throws Exception
>>> + {
>>> + RandomAccessFile controlFile = null;
>>> + try
>>> + {
>>> + int testModeNoSyncMarkerPosition = 29;
>>> + String derbyHome = System.getProperty("derby.system.home");
>>> + controlFile = new
>>> RandomAccessFile(derbyHome+"/wombat/log/log.ctrl","r");
>>> + controlFile.seek(testModeNoSyncMarkerPosition);
>>> + report("log.ctrl file has testMode NoSync marker value =
>>> "+ controlFile.readByte());
>>> + }
>>> + finally
>>> + {
>>> + if(controlFile != null)
>>> + controlFile.close();
>>> + + }
>>> + }
>>> + + public static void report(String msg)
>>> + {
>>> + System.out.println(msg);
>>> + }
>>> + +}
>>> +
>>> +
>>> +
>>>
>>> Property changes on:
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>>>
>>> ___________________________________________________________________
>>> Name: svn:eol-style
>>> + native
>>>
>>> Index:
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
>>>
>>> ===================================================================
>>> ---
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
>>> (revision 165265)
>>> +++
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
>>> (working copy)
>>> @@ -23,6 +23,7 @@
>>> TransactionTable.sql
>>> TransactionTable_app.properties
>>> TransactionTable_derby.properties
>>> +TestNoSyncMode_derby.properties
>>> access.sql
>>> access_app.properties
>>> access_derby.properties
>>> Index:
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>>>
>>> ===================================================================
>>> ---
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>>> (revision 0)
>>> +++
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>>> (revision 0)
>>> @@ -0,0 +1 @@
>>> +derby.system.testMode=true
>>>
>>> Property changes on:
>>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>>>
>>> ___________________________________________________________________
>>> Name: svn:eol-style
>>> + native
>>>
>>> Index:
>>> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>>>
>>> ===================================================================
>>> ---
>>> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>>> (revision 0)
>>> +++
>>> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>>> (revision 0)
>>> @@ -0,0 +1,3 @@
>>> +num successful inserts = 500
>>> +Is warning message about derby.system.testMode present in derby.log
>>> =true
>>> +log.ctrl file has testMode NoSync marker value = 1
>>> Index:
>>> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
>>>
>>> ===================================================================
>>> ---
>>> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
>>> (revision 165265)
>>> +++
>>> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
>>> (working copy)
>>> @@ -4,3 +4,4 @@
>>> store/longColumn.sql
>>> store/madhare.sql
>>> store/streamingColumn.java
>>> +store/TestNoSyncMode.java
>>
>>
>>
>>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Mike Matrigali <mi...@sbcglobal.net>.
As I have posted before I have concerns about this mode, as it can
definitely produce a database which can not boot. But the discussions
here convinced me
that it was useful for a number of applications, so now believe it
should be checked in. I definitely have no career path in marketing
as my first take at a name was corrupt_your_db=true :-) . So testMode
seemed ok to me, but if another name is better that is fine with me
also.
Going forward I would like to see more work done to implement the
relaxed durability option suresh and I were discussing. I believe
that with some code changes file allocation, log write and many of
the data write sync's can be eliminated and still guarantee a bootable
database. This mode would not guarantee a committed transaction,
but would guarantee that database on a disk with enough free space
would boot and that the db would represent only complete transactions
(either fully applied or not). This option would
be slower than what is available from this patch so I believe both
features are useful.
David Van Couvering wrote:
> Hi, Sunitha. Thanks for your work on this. My comment is more a
> "marketing" comment than a technical one. I disagree that this is
> useful only for testing and development. As I mentioned in previous
> emails, there are a number of customers who may find this very useful
> indeed, who are willing to trade off 100% guarantee of all transactions
> being available on recovery for significant increases in performance.
>
> I wouldn't get into this debate were it not for the fact that the
> property you have created is called "testMode." I would much rather
> have it not imply it's only for testing, with a name like "delayedWrite"
> or "relaxedDurability" or some such.
>
> Thanks,
>
> David
>
> Sunitha Kambhampati wrote:
>
>> A little background: Sometime earlier on the list, Dan posted a fix to
>> make derby go faster with relaxed durability with some flags. The
>> post is at
>> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>
>> This mode is very useful for unit testing or at development time when
>> recoverability is not required.
>> Basically in this mode, syncs are disabled for logs, data writes at
>> checkpoint, page allocation when file is grown; - what this means is
>> that data is not flushed all the way to the disk and in most cases i/o
>> cost is not involved. Note, code already exists in Derby to do this.
>> So for Derby 218, This patch addresses the following requirements:
>> 1) Have a single property to enable this relaxed durability mode, so
>> it is easy for users to enable it.
>> 2) Print message to derby.log that this mode is enabled
>> 3) A way to report boot errors that may be because of this option
>> being enabled. What this maps to is - have a marker to recognize that
>> database was booted in this mode, and then on subsequent boot; if
>> errors happen during recovery - report a message that it could have
>> happened because of this mode being set.
>>
>> Changes are not much. svn stat
>> M java\engine\org\apache\derby\impl\store\raw\log\LogToFile.java
>> M
>> java\engine\org\apache\derby\impl\store\raw\data\BaseDataFileFactory.java
>> M java\engine\org\apache\derby\impl\store\raw\data\RAFContainer.java
>> M java\engine\org\apache\derby\iapi\reference\MessageId.java
>> M java\engine\org\apache\derby\iapi\reference\Property.java
>> M java\engine\org\apache\derby\loc\messages_en.properties
>> A
>> java\testing\org\apache\derbyTesting\functionTests\tests\store\TestNoSyncMode.java
>>
>> M
>> java\testing\org\apache\derbyTesting\functionTests\tests\store\copyfiles.ant
>>
>> A
>> java\testing\org\apache\derbyTesting\functionTests\tests\store\TestNoSyncMode_derby.properties
>>
>> A
>> java\testing\org\apache\derbyTesting\functionTests\master\TestNoSyncMode.out
>>
>> M
>> java\testing\org\apache\derbyTesting\functionTests\suites\storemats.runall
>>
>>
>> Since this is a longish email , for those who may not read the rest
>> of it, here are the testing results
>>
>> Testing results:
>> - I ran derbyall with 1.4.2 jvm and all tests passed. - I ran the
>> storeall suite separately both with setting the derby.system.testMode
>> property to true and without it. with this property set, the
>> storeall suite ran about 2 times as fast.
>> -------------------------------
>>
>> Below I explain how the patch addresses the above requirements and
>> try to provide details on how I went about making those changes
>>
>> 0) Note
>> 1) A single property has been added to enable this relaxed durability
>> option. The property name is derby.system.testMode and takes in value
>> true or false. By default it is false. It can be set as a command line
>> option to the JVM when starting the application or within the
>> application or in the derby.properites file. Property is loaded at
>> boot time, so for it to have an effect you need to enable it at boot
>> time. More comments added in code itself. see variable
>> TESTMODE_NO_SYNC = "derby.system.testMode"; in Property.java.
>>
>> (In this patch, I have used 'no_sync' as suffix in variable names
>> because I think with respect to store - that is what this mode is all
>> about - disabling syncs for the cases already mentioned earlier in
>> this mail)
>>
>> I chose the property name derby.system.testMode for this
>> - represents a higher concept as to when one would use relaxed
>> durability (no sync) option.
>> - mostly it should be enabled only when data is not important and
>> ideally maybe for testing and development purposes,
>> - also with the hope that the word 'testMode' would prompt users to
>> look this property up before using it in a production like environment
>> where it may not necessarily be appropriate.
>>
>> Code changes for this:
>> - Added this new property derby.system.testMode in
>> java\engine\org\apache\derby\iapi\reference\Property.java
>>
>> - Removed the following properties from Property.java as they are no
>> longer required.
>> derby.storage.dataNotSyncedAtCheckPoint=true ( I'll refer to
>> this as DNSAC in notes below)
>> derby.storage.dataNotSyncedAtAllocation=true ( I'll refer to
>> this as DNSAA in notes below)
>> derby.storage.logNotSynced=true (I'll refer to this as
>> LNS in notes below)
>>
>> - Previously code existed for enabling the DNSAC, DNSAA and LNS
>> options conditional on Performance.MEASURE
>>
>> So how it works is , the 2 variables in BaseDataFileFactory.java are
>> used to control if syncs happen or not for data pages at allocation
>> and at checkpoint.
>> dataNotSyncedAtAllocation dataNotSyncedAtCheckpoint
>>
>> And in java/engine/org/apache/derby/impl/store/raw/log/LogToFile, the
>> logNotSynced variable is used to control if syncs happen for the logs
>> are not.
>>
>> These variables are enabled (set to true) if Performance.MEASURE is
>> set to true, and if the DNSAC, and DSNAA propertie are enabled.
>>
>> So all that is required now is
>> - remove conditional on Performance.MEASURE in these cases, instead
>> use the derby.system.testMode property to enable them . This happens
>> in the boot methods
>> - make sure to remove any conditionals on Performance.MEASURE that is
>> used to disable syncs but instead control it by the variables
>> mentioned above.. ie e.g. dataNotSyncedAtAllocation in
>> BaseDataFileFactory.java ...
>> - remove reading of the DNSAC, DNSAA,LNS property as they are not
>> needed anymore
>>
>> Changes were needed to following files - i)
>> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
>> (check boot method)
>> ii) java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
>> iii) java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>> (check boot method).
>>
>> 2) Write to the derby.log a warning message
>>
>> Needed to add a new message.
>> Messages need to be translated, so I made the following changes
>>
>> i) added a variable in
>> java/engine/org/apache/derby/iapi/reference/MessageId.java to
>> represent this new message.
>> String STORE_TESTMODE_NO_SYNC = "D013";
>>
>> ii) Message content added to
>> java/engine/org/apache/derby/loc/messages_en.properties
>> D013=WARNING: {0} is set to true. In this mode, there is no guarantee
>> that the system will recover a system crash or JVM termination. Enable
>> this property only when there is no need for recoverability \n
>>
>> iii) In the boot process, rawstore boot calls logfactory boot, so the
>> first time the derby.system.testMode property is read, it is in
>> rawstore, so added code to print the warning message in
>> BaseDataFileFactory.boot(..)
>>
>>
>> 3) A way to report boot errors that may be because of this option
>> being enabled. What this maps to is - have a marker to recognize that
>> database was booted in this mode, and then on subsequent boot if
>> errors happen during recovery report a message that it could have
>> happened because of this mode being set.
>>
>> - To write a marker out , log.ctrl file is used, it has a few spare
>> bytes so no major changes needed here. ( ie no disk format changes.... )
>> Check the method readControlFile in
>> java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>>
>> - Used the first spare byte available in log control file which will
>> be used to store information about if derby.system.testMode is set or
>> not.
>> Added variable TESTMODE_NO_SYNC_FLAG_OFFSET to represent this offset
>> in LogToFile.java
>>
>> - The value written out if this property is enabled is
>> TESTMODE_NO_SYNC_TRUE = 0x1 else a 0 is written out. ( I didnt like
>> to put the 0 but wasnt feeling too strong to adding a new static byte
>> variable either.. and as rest of the code around it in
>> writeControlFile seems to use 0 as is , I just followed the same
>> approach).
>>
>> - Change made to readControlFile to read in the value for the
>> testmode case when Logfactory is booted, the flag is read and value
>> stored
>> in variable called wasDBInTestModeNoSync. This variable keeps track
>> of if database was previously booted in the derby.system.testMode or
>> not. Comes in use for error reporting.
>>
>> - Also added a message to report to the derby.log incase database was
>> previously booted with derby.system.testMode set to true. Change to
>> messages_en.properties and MessageId.java.
>> L020=WARNING: The database was previously booted with {0} set to true.
>> Note that this mode {0}=true does not guarantee recoverability \n
>>
>> little on the flow with respect to writeControlFile .. if you look at
>> the code in LogToFile for boot and recover, writeControlFile is called
>> a couple of times.. to read the checkpoint instant etc..
>> - For my changes, I am just copy/paste the comments from
>> writeControlFile(...) , Note case4 below .. which is the interesting
>> one.
>>
>> // A spare byte at offset TESTMODE_NO_SYNC_FLAG_OFFSET
>> // is used to write out if database was in
>> derby.system.testMode=true mode
>> // or not.
>> // This byte will have one of the two values
>> // - TESTMODE_NO_SYNC_TRUE to represent database was booted
>> // in this mode
>> // - 0 to represent database was not booted in this mode
>> // // The sole purpose of this flag in control file is
>> to help
>> // identify any recovery problems that might happen as a result
>> of this
>> // mode being set.
>> //
>> // Possible scenarios. In table below, cases are listed giving
>> // the value of derby.system.testMode if it was enabled or not
>> at boot time
>> // ---------------------------------------------------------------
>> // Case Previous Current Action , what should
>> the flag be set to in log.ctrl
>> // Boot Boot file
>> // --------------------------------------------------------------
>> // 1 - true write
>> TESTMODE_NO_SYNC_TRUE
>> // 2 - false write 0
>> // 3 false false write 0
>> // 4 true false write
>> TESTMODE_NO_SYNC_TRUE
>> // 5 true true write
>> TESTMODE_NO_SYNC_TRUE
>> //
>> // Case 4 is the interesting case here.
>> // one cannot write out the derby.system.testMode is disabled
>> just yet
>> // because it is possible that the database recovery might fail
>> and on subsequent
>> // restarts this state would be lost. So only when recovery is
>> successful, will
>> // we update the flag in the log control file to indicate that
>> the derby.system.testMode
>> // is not enabled. (This will happen at the end of recovery ,
>> see recover method)
>> //
>> // Case 1, 2 is when database is created fresh with this
>> property enabled.
>> //
>> // wasDBInTestModeNoSync has information if database was
>> previously booted
>> // in derby.system.testMode=true mode
>>
>> To handle case 4, changes went into recover () method , if database
>> recovery is successful only then we update the flag in the control
>> file to say database is not booted with this property enabled. Since
>> there was no method available to update the log control file, added a
>> new method updateTestModeFlagInCtrlFile(byte value) to do that.
>>
>> So now that changes are done to write the marker to the control file
>> and to read it, it is necessary to take care of case when error happens.
>>
>> - added a new message to report that cause of an error could be
>> related to this property being set
>> added a new variable in MessageId.LOG_TESTMODE_NO_SYNC_ERR in
>> java/engine/org/apache/derby/iapi/reference/MessageId.java
>> and the message to
>> java/engine/org/apache/derby/loc/messages_en.properties
>> L021=WARNING: The database was either previously booted or is
>> currently booted with {0} set to true. Note that this mode {0}=true
>> does not guarantee recoverability, and is probably what might have
>> caused this boot error \n
>> - added MessageId.LOG_TESTMODE_NO_SYNC_ERR in
>> java/engine/org/apache/derby/iapi/reference/MessageId.java
>>
>> Added a new method logErrMsgForTestModeNoSync() in LogToFile.java to
>> print out this message if any error happens when database is in the
>> influence of this property.
>>
>> In deciding what the best place would be to call the
>> logErrMsgForTestModeNoSync, I debated between adding it in
>> markCorrupt() versus logErrMsg(..). It seemed like if error happened
>> during boot - the flow was to call markCorrupt which would call
>> logErrMsg. Some error messages seem to call logErrMsg(..) directly.
>> So I picked the logErrMsg as it covered most of the errors thrown
>> during boot/recovery that would be related to something with this
>> property being set. -------------------------------------------
>>
>> TESTING
>>
>> 1) I added one new java file per the derby test harness, to test
>> the following
>> - check if the property is enabled correctly by timing some inserts
>> into a table.
>> - check if the correct flag (TESTMODE_NO_SYNC_TRUE) is written out
>> into the log.ctrl file
>> - check if the derby.log has the warning message.
>>
>> Changes include
>> i)Added new test to
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>>
>> ii)Added
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>>
>>
>> TestNoSyncMode_derby.properties has
>> derby.system.testMode=true
>>
>> This property file is needed so when test is run it picks up this
>> property.
>>
>> iii)The TestNoSyncMode_derby.properties is added to copyfiles.ant so
>> it will be copied over when compiling derby tests.
>>
>> iv) To enable this new test as part of the store suite, I modified the
>> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
>>
>> added store/TestNoSyncMode.java
>>
>> v) To get my correct output file, first i just put an initial empty
>> file in
>> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>>
>>
>> Ran the test after compiling source; java
>> org.apache.derbyTesting.functionTests.harness.RunTest
>> store/TestNoSyncMode.java
>> Then I updated the out file in the master directory, after checking if
>> the TestNoSyncMode.out file was correct.
>>
>> 2) For the error messages on a boot error, it is difficult to put it
>> in a test, so I checked this in the debugger and it works ok.
>>
>> Meanwhile, Suresh Thalamati posted on the list that he is working on a
>> corruptible storage factory, once that is there - I am hoping I could
>> use that to have a test to check the error messages for boot errors.
>>
>> As far as I can tell, this does not affect upgrade and such since we
>> are not changing the disk format etc.. ..There is one spare byte in
>> log.ctrl file that is being used now as a result of this change and
>> this byte value should not have been used to represent anything useful
>> by any earlier version
>>
>> Testing results (already mentioned in the beginning of this email).
>>
>> Please give your comments. Thanks,
>> Sunitha.
>>
>>
>> ------------------------------------------------------------------------
>>
>> Index: java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>> ===================================================================
>> --- java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>> (revision 165265)
>> +++ java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>> (working copy)
>> @@ -265,7 +265,38 @@
>>
>> /* Log Control file flags. */
>> private static final byte IS_BETA_FLAG = 0x1;
>> -
>> +
>> + /**
>> + * When the derby.system.testMode property is enabled, the store
>> + * system will not force sync calls in the following cases
>> + * - for the log file at each commit
>> + * - for the log file before data page is forced to disk
>> + * - for page allocation when file is grown
>> + * - for data writes during checkpoint
>> + * This means the recovery system may not work properly
>> + * In order that we recognize this case that the database was
>> previously
>> + * booted in this mode, this value is written out
>> + * into the log control file. This will help prevent us from
>> + * wasting time to resolve issues in such cases. + * @see
>> org.apache.derby.iapi.reference.Property#TESTMODE_NO_SYNC
>> + */
>> + private static final byte TESTMODE_NO_SYNC_TRUE = 0x1;
>> +
>> + /**
>> + * A byte in the log control file is used to store information
>> + * about if the database is booted in derby.system.testMode mode
>> + * The first available spare byte that is available for this
>> purpose is + * after 5 ints ( 4bytes each), a long ( 8 bytes) and
>> 1 byte in the log control
>> + * file. Hence the offset is calculated as follows
>> + */
>> + private static final int TESTMODE_NO_SYNC_FLAG_OFFSET = 5*4 + 8
>> + 1;
>> + + /**
>> + * keeps track of if the database was booted previously with
>> + * derby.system.testMode=true + */
>> + private static boolean wasDBInTestModeNoSync = false;
>> + /* to err on the conservative side, unless otherwise set,
>> assume log
>> * archive is ON */
>> @@ -362,7 +393,7 @@
>> // log goes to the log subdirectory underneath the data directory
>> String logDevice;
>>
>> - // debug only flag - disable syncing of log file for debugging
>> performance.
>> + // disable syncing of log file when running in
>> derby.system.testMode enabled
>> private boolean logNotSynced = false;
>>
>> private boolean logArchived = false;
>> @@ -403,6 +434,7 @@
>>
>> private CRC32 checksum = new CRC32(); // holder for the checksum
>>
>> + protected static int CHECKSUM_SIZE = 8; // checksum size in bytes
>>
>>
>> /**
>> @@ -1194,8 +1226,28 @@
>> tf.resetTranId();
>> }
>>
>> - // done with recovery
>> -
>> + // If we have reached here successfully, that means recovery
>> + // was successful
>> + + // Now that database has recovered successfully and
>> if it
>> + // is booted with derby.system.testMode=false mode, there is no
>> + // need to store information that database was booted
>> previously in + // derby.system.testMode=true mode. + //
>> It is safe to update the marker in log.ctrl file to say
>> + // that the derby.system.testMode in not being used
>> + + // Need to write to the log.ctrl file as well as the log
>> mirror file
>> + if( wasDBInTestModeNoSync && !logNotSynced )
>> + {
>> + // write to log control file and the mirror file that the
>> testmode + // is not used now
>> + if(!updateTestModeFlagInCtrlFile((byte)0))
>> + throw StandardException.newException(
>> + SQLState.LOG_CONTROL_FILE, getControlFileName());
>> + + wasDBInTestModeNoSync = false;
>> + } +
>> /////////////////////////////////////////////////////////////
>> // setup checktpoint daemon
>> /////////////////////////////////////////////////////////////
>> @@ -1207,6 +1259,99 @@
>> }
>> }
>>
>> + /**
>> + * Update the flag that represents whether + *
>> derby.system.testMode is enabled or not in both the log control file
>> + * as well as the mirror control file
>> + * <BR>
>> + * Basically, Read the control file, + * update the flag to
>> the new passed in value + * recalculate the checksum and write it
>> out to the log control file
>> + * <P> MT- synchronized by caller
>> + * @param value to set
>> + * @return false if the update didnt happen successfully, else true
>> + * @throws IOException
>> + * @throws StandardException
>> + * @see #readControlFile
>> + * @see #writeControlFile(StorageFile, long)
>> + */
>> + private boolean updateTestModeFlagInCtrlFile(byte value)
>> + {
>> + StorageRandomAccessFile logControlFile = null;
>> + byte barray[] = null;
>> + StorageFile ctrlFile = null;
>> + + try
>> + {
>> + ctrlFile = getControlFileName();
>> + logControlFile = privRandomAccessFile(ctrlFile, "rw");
>> + if (!privCanWrite(ctrlFile))
>> + return false;
>> + + // retrieve all except the checksum bytes
>> + barray = new byte[(int) logControlFile.length() -
>> CHECKSUM_SIZE];
>> + logControlFile.readFully(barray);
>> + + if (SanityManager.DEBUG)
>> + {
>> + if (SanityManager.DEBUG_ON(DBG_FLAG))
>> + {
>> + SanityManager.DEBUG(DBG_FLAG,
>> + "Updating derby.system.testMode marker
>> written out"+
>> + "to log control file: prev value = " +
>> + barray[TESTMODE_NO_SYNC_FLAG_OFFSET] + " to
>> "+ value); + }
>> + }
>> + // update the byte at position that represents whether
>> + // derby.system.testMode was used
>> + barray[TESTMODE_NO_SYNC_FLAG_OFFSET] = value;
>> + + // write back into file the updated value
>> and also compute + // the newchecksum and write it to file
>> + logControlFile.seek(0);
>> + logControlFile.write(barray);
>> + checksum.reset();
>> + checksum.update(barray, 0, barray.length);
>> + logControlFile.writeLong(checksum.getValue());
>> + syncFile(logControlFile);
>> + logControlFile.close();
>> +
>> + // write the same data to mirror control file
>> + ctrlFile = getMirrorControlFileName();
>> + logControlFile =
>> + privRandomAccessFile(ctrlFile, "rw");
>> + if (!privCanWrite(ctrlFile))
>> + return false;
>> + logControlFile.seek(0);
>> + logControlFile.write(barray);
>> + logControlFile.writeLong(checksum.getValue());
>> + syncFile(logControlFile);
>> + }
>> + catch(IOException ioe)
>> + {
>> + logControlFile = null;
>> + return false;
>> + }
>> + catch(StandardException se)
>> + {
>> + logControlFile = null;
>> + return false;
>> + }
>> + finally
>> + {
>> + try
>> + { + if (logControlFile != null)
>> + logControlFile.close();
>> + }
>> + catch(IOException ioe2)
>> + {
>> + logControlFile = null;
>> + return false;
>> + }
>> + }
>> + return true;
>> + }
>> /**
>> Checkpoint the rawStore.
>>
>> @@ -2142,10 +2287,61 @@
>>
>> //
>> // write some spare bytes after 2.0 we have 3 + 2(8) spare
>> bytes.
>> + // now with v10.1.0.0 we have 2 +2(8) spare bytes as one of
>> the spare
>> + // byte is used as a marker to write out if system is runinng
>> + // in derby.system.testMode=true or not.
>> + long spare = 0;
>> + + // A spare byte at offset TESTMODE_NO_SYNC_FLAG_OFFSET
>> + // is used to write out if database was in
>> derby.system.testMode=true mode
>> + // or not. + // This byte will have one of the two values
>> + // - TESTMODE_NO_SYNC_TRUE to represent database was booted
>> + // in this mode + // - 0 to represent database was
>> not booted in this mode
>> + // + // The sole purpose of this flag in control file
>> is to help
>> + // identify any recovery problems that might happen as a
>> result of this
>> + // mode being set. + // + // Possible
>> scenarios. In table below, cases are listed giving + // the
>> value of derby.system.testMode if it was enabled or not at boot time
>> + //
>> ---------------------------------------------------------------
>> + // Case Previous Current Action , what should the
>> flag be set to in log.ctrl + // Boot Boot
>> file
>> + //
>> --------------------------------------------------------------
>> + // 1 - true write
>> TESTMODE_NO_SYNC_TRUE + // 2 - false
>> write 0 + // 3 false false write 0
>> + // 4 true false write
>> TESTMODE_NO_SYNC_TRUE + // 5 true true
>> write TESTMODE_NO_SYNC_TRUE
>> + // + // Case 4 is the interesting case here.
>> + // one cannot write out the derby.system.testMode is disabled
>> just yet
>> + // because it is possible that the database recovery might
>> fail and on subsequent
>> + // restarts this state would be lost. So only when recovery
>> is successful, will + // we update the flag in the log control
>> file to indicate that the derby.system.testMode
>> + // is not enabled. (This will happen at the end of recovery
>> , see recover method) + // + // Case 1, 2 is when
>> database is created fresh with this property enabled.
>> + // + // wasDBInTestModeNoSync has information if
>> database was previously booted
>> + // in derby.system.testMode=true mode
>> + if( !wasDBInTestModeNoSync ) // derby.system.testMode=false
>> + {
>> + // in this case, no need to write out any special marker
>> + // for derby.system.testMode=false case.
>> + if(!logNotSynced)
>> + daos.writeByte(0); + else
>> + daos.writeByte(TESTMODE_NO_SYNC_TRUE); + }
>> + else
>> + daos.writeByte(TESTMODE_NO_SYNC_TRUE);
>> + daos.writeByte(0);
>> daos.writeByte(0);
>> - daos.writeByte(0);
>> daos.writeLong(spare);
>> daos.flush();
>> // write the checksum for the control data written
>> @@ -2281,7 +2477,24 @@
>> onDiskMinorVersion = dais.readInt();
>> int dbBuildNumber = dais.readInt();
>> int flags = dais.readByte();
>> -
>> +
>> + // check if the database was running previously with
>> + // derby.system.testMode=true mode
>> + // if database was running previously in
>> derby.system.testMode=true
>> + // and if on a restart - recovery fails we want to be
>> able
>> + // to report that the boot error could have happened
>> + // because of this property
>> + wasDBInTestModeNoSync =(dais.readByte() &
>> TESTMODE_NO_SYNC_TRUE) != 0;
>> + + if (SanityManager.DEBUG)
>> + {
>> + if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
>> + SanityManager.DEBUG(LogToFile.DBG_FLAG,
>> + "log control file, was
>> derby.system.testMode enabled = " + +
>> wasDBInTestModeNoSync);
>> + }
>> + +
>> onDiskBeta = (flags & IS_BETA_FLAG) != 0;
>>
>> if (onDiskBeta)
>> @@ -2794,19 +3007,15 @@
>> isWriteSynced = false;
>> }
>>
>> - if (Performance.MEASURE)
>> + // if system is running with derby.system.testMode enabled
>> + // log records and log file are not synced, so
>> + // set flag to disable log syncs
>> + if (PropertyUtil.getSystemBoolean(Property.TESTMODE_NO_SYNC))
>> {
>> - // debug only flag - disable syncing of log.
>> - logNotSynced = -
>> PropertyUtil.getSystemBoolean(Property.STORAGE_LOG_NOT_SYNCED);
>> -
>> - if (logNotSynced)
>> - {
>> - Monitor.logMessage("logNotSynced = true");
>> - //if log is Not being synced;files should not be open
>> in write sync mode
>> - isWriteSynced = false;
>> - }
>> -
>> + // disable syncing of log.
>> + logNotSynced = true;
>> + //if log is Not being synced;files should not be open
>> in write sync mode
>> + isWriteSynced = false;
>> }
>>
>> // try to access the log
>> @@ -2830,6 +3039,18 @@
>> if (privExists(logControlFileName))
>> {
>> checkpointInstant =
>> readControlFile(logControlFileName, startParams);
>> + // in case system was running previously with
>> derby.system.testMode=true
>> + // then print a message to the derby log
>> + if(wasDBInTestModeNoSync)
>> + {
>> + // print message stating that the database was
>> + // previously running with derby.system.testMode=true
>> + // mode
>> + Monitor.logMessage(MessageService.getTextMessage(
>> + MessageId.LOG_WAS_IN_TESTMODE_NO_SYNC,
>> + Property.TESTMODE_NO_SYNC));
>> + }
>> +
>> if (checkpointInstant ==
>> LogCounter.INVALID_LOG_INSTANT &&
>>
>> getMirrorControlFileName().exists())
>> checkpointInstant =
>> @@ -2879,8 +3100,9 @@
>> // blow away the log file if possible
>> if (!privDelete(logFile) && logFileNumber == 1)
>> {
>> + logErrMsgForTestModeNoSync();
>> throw StandardException.newException(
>> - SQLState.LOG_INCOMPATIBLE_FORMAT,
>> dataDirectory);
>> +
>> SQLState.LOG_INCOMPATIBLE_FORMAT,dataDirectory);
>> }
>>
>> // If logFileNumber > 1, we are not going to
>> write that file just
>> @@ -2913,6 +3135,7 @@
>>
>> if (!privDelete(logFile))
>> {
>> + logErrMsgForTestModeNoSync();
>> throw StandardException.newException(
>> SQLState.LOG_INCOMPATIBLE_FORMAT,
>> dataDirectory);
>> @@ -3584,15 +3807,8 @@
>> }
>> else
>> {
>> - if (Performance.MEASURE)
>> - {
>> - if (!logNotSynced)
>> - logOut.syncLogAccessFile();
>> - }
>> - else
>> - {
>> - logOut.syncLogAccessFile();
>> - }
>> + if (!logNotSynced)
>> + logOut.syncLogAccessFile();
>> }
>>
>> syncSuceed = true;
>> @@ -3925,6 +4141,7 @@
>> */
>> protected void logErrMsg(String msg)
>> {
>> + logErrMsgForTestModeNoSync();
>> Monitor.logTextMessage(MessageId.LOG_BEGIN_ERROR);
>> Monitor.logMessage(msg);
>> Monitor.logTextMessage(MessageId.LOG_END_ERROR);
>> @@ -3936,6 +4153,7 @@
>> */
>> protected void logErrMsg(Throwable t)
>> {
>> + logErrMsgForTestModeNoSync();
>> if (corrupt != null)
>> {
>> Monitor.logTextMessage(MessageId.LOG_BEGIN_CORRUPT_STACK);
>> @@ -3951,6 +4169,22 @@
>> }
>> }
>>
>> + /**
>> + * In case of boot errors, and if database is either booted
>> + * with derby.system.testMode being set or was previously booted
>> in this
>> + * mode, mention in the error message that the error is probably
>> + * because the derby.system.testMode was set. + * Dont want
>> to waste time to resolve issues in such
>> + * cases
>> + * <p>
>> + * MT - not needed, informational only
>> + */
>> + protected void logErrMsgForTestModeNoSync()
>> + {
>> + if(logNotSynced || wasDBInTestModeNoSync)
>> + Monitor.logTextMessage(MessageId.LOG_TESTMODE_NO_SYNC_ERR);
>> + }
>> +
>> private void printErrorStack(Throwable t)
>> {
>> Monitor.logMessage("-------------------------\n");
>> Index:
>> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
>> ===================================================================
>> ---
>> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
>> (revision 165265)
>> +++
>> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
>> (working copy)
>> @@ -179,11 +179,11 @@
>> private static final String LINE =
>> "----------------------------------------------------------------";
>>
>> - // debug only flag - disable syncing of data during page allocation.
>> - boolean dataNotSyncedAtAllocation;
>> + // disable syncing of data during page allocation.
>> + boolean dataNotSyncedAtAllocation = false;
>>
>> - // debug only flag - disable syncing of data during checkpoint.
>> - boolean dataNotSyncedAtCheckpoint;
>> + // disable syncing of data during checkpoint.
>> + boolean dataNotSyncedAtCheckpoint = false;
>>
>> // these fields can be accessed directly by subclasses if it needs a
>> // different set of actions
>> @@ -375,29 +375,24 @@
>>
>> droppedTableStubInfo = new Hashtable();
>>
>> - if (Performance.MEASURE)
>> + /**
>> + * If derby.system.testMode=true then set flags to +
>> * disable sync of data pages at allocation when file is grown,
>> + * disable sync of data writes during checkpoint
>> + */
>> + if (PropertyUtil.getSystemBoolean(Property.TESTMODE_NO_SYNC))
>> {
>> - // debug only flag - disable syncing of data during
>> checkpoint.
>> - dataNotSyncedAtCheckpoint = -
>> PropertyUtil.getSystemBoolean(
>> - Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT);
>> + // - disable syncing of data during checkpoint.
>> + dataNotSyncedAtCheckpoint = true;
>>
>> - // debug only flag - disable syncing of data during page
>> allocation.
>> - dataNotSyncedAtAllocation = -
>> PropertyUtil.getSystemBoolean(
>> - Property.STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION);
>> -
>> - if (dataNotSyncedAtCheckpoint)
>> - Monitor.logMessage(
>> - "Warning: " + -
>> Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT +
>> - "set to true.");
>> -
>> - if (dataNotSyncedAtAllocation)
>> - Monitor.logMessage(
>> - "Warning: " + -
>> Property.STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION +
>> - "set to true.");
>> + // - disable syncing of data during page allocation.
>> + dataNotSyncedAtAllocation = true;
>> + + // log message stating that
>> derby.system.testMode
>> + // has been enabled. +
>> Monitor.logMessage(MessageService.getTextMessage(
>> + MessageId.STORE_TESTMODE_NO_SYNC,
>> + Property.TESTMODE_NO_SYNC));
>> }
>>
>> fileHandler = new RFResource( this);
>> Index: java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
>> ===================================================================
>> ---
>> java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
>> (revision 165265)
>> +++
>> java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
>> (working copy)
>> @@ -325,15 +325,8 @@
>> dataFactory.writeInProgress();
>> try
>> {
>> - if (Performance.MEASURE)
>> - {
>> - if (!dataFactory.dataNotSyncedAtAllocation)
>> - fileData.sync( false);
>> - }
>> - else
>> - {
>> + if (!dataFactory.dataNotSyncedAtAllocation)
>> fileData.sync( false);
>> - }
>> }
>> finally
>> {
>> @@ -504,16 +497,9 @@
>> dataFactory.writeInProgress();
>> inwrite = true;
>>
>> - if (Performance.MEASURE)
>> - {
>> - if (!dataFactory.dataNotSyncedAtAllocation)
>> - fileData.sync( false);
>> - }
>> - else
>> - {
>> + if (!dataFactory.dataNotSyncedAtAllocation)
>> fileData.sync( false);
>> - }
>> - }
>> + }
>> catch (IOException ioe)
>> {
>> // The disk may have run out of space. @@ -629,15
>> +615,9 @@
>> dataFactory.writeInProgress();
>> try
>> {
>> - if (Performance.MEASURE)
>> - {
>> - if (!dataFactory.dataNotSyncedAtCheckpoint)
>> - file.sync( false);
>> - }
>> - else
>> - {
>> - file.sync( false);
>> - }
>> + if (!dataFactory.dataNotSyncedAtCheckpoint)
>> + file.sync( false);
>> +
>> }
>> finally
>> {
>> Index: java/engine/org/apache/derby/iapi/reference/MessageId.java
>> ===================================================================
>> --- java/engine/org/apache/derby/iapi/reference/MessageId.java
>> (revision 165265)
>> +++ java/engine/org/apache/derby/iapi/reference/MessageId.java
>> (working copy)
>> @@ -58,8 +58,10 @@
>> String LOG_CANNOT_CREATE_NEW_DUETO = "L017";
>> String LOG_MAYBE_INCONSISTENT = "L018";
>> String LOG_TRANS_LOG_SCAN = "L019";
>> + String LOG_WAS_IN_TESTMODE_NO_SYNC = "L020"; // system was
>> running in derby.system.testMode set + String
>> LOG_TESTMODE_NO_SYNC_ERR = "L021"; // hint that error could be
>> because + //
>> derby.system.testMode was set
>>
>> -
>> /*
>> * Raw Store data
>> */
>> @@ -75,6 +77,7 @@
>> String STORE_BACKUP_ABORTED = "D010";
>> String STORE_REMOVED_BACKUP = "D011";
>> String STORE_BACKUP_COMPLETED = "D012";
>> + String STORE_TESTMODE_NO_SYNC = "D013"; // for
>> derby.system.testMode is set
>>
>>
>> /*
>> Index: java/engine/org/apache/derby/iapi/reference/Property.java
>> ===================================================================
>> --- java/engine/org/apache/derby/iapi/reference/Property.java
>> (revision 165265)
>> +++ java/engine/org/apache/derby/iapi/reference/Property.java
>> (working copy)
>> @@ -368,55 +368,47 @@
>> <P>
>> */
>> String STORAGE_TEMP_DIRECTORY = "derby.storage.tempDirectory";
>> -
>> +
>> /**
>> - * derby.storage.dataNotSyncedAtCheckPoint
>> + * derby.system.testMode
>> * <p>
>> - * When set, the store system will not force a sync() call on the
>> - * containers during a checkpoint.
>> + * When set, the store system will not force sync calls in the
>> following
>> + * cases + * - for the log file at each commit
>> + * - for the log file before data page is forced to disk
>> + * - for page allocation when file is grown
>> + * - for data writes during checkpoint
>> * <p>
>> - * An internal debug system only flag. The recovery system will not
>> - * work properly if this flag is enabled, it is provided to do
>> performance
>> - * debugging to see whether the system is I/O bound based on
>> checkpoint
>> - * synchronous I/O.
>> + * That means, when this property is set to true
>> + * - a commit no longer guarantees that the transaction's
>> modification
>> + * will survive a system crash or JVM termination
>> + * - the database may not recover successfully upon restart
>> + * - a near full disk at runtime may cause unexpected errors
>> * <p>
>> - *
>> - **/
>> - public static final String STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT
>> = - "derby.storage.dataNotSyncedAtCheckPoint";
>> -
>> - /**
>> - * derby.storage.dataNotSyncedAtAllocation
>> + * This property is provided for performance reasons and should
>> ideally
>> + * only be used when there is no requirement for the database to
>> recover.
>> + * <BR> + * One sample use would be to enable this property
>> when using Derby as a test
>> + * database, where recoverability is not a concern but
>> performance is important.
>> + * <BR>
>> + * Default value is false
>> + * <BR>
>> + * Valid Values
>> + * Valid values are true or false
>> + * <BR>
>> + * Example
>> + * derby.system.testMode=true
>> + * One can set this as a command line option to the JVM when
>> starting the
>> + * application or in the derby.properties file
>> + * <BR>
>> + * This property is static; if you change it while Derby is
>> running, + * the change does not take effect until you reboot.
>> * <p>
>> - * When set, the store system will not force a sync() call on the
>> - * containers when pages are allocated.
>> - * <p>
>> - * An internal debug system only flag. The recovery system will not
>> - * work properly if this flag is enabled, it is provided to do
>> performance
>> - * debugging to see whether the system is I/O bound based on page
>> allocation
>> - * synchronous I/O.
>> - * <p>
>> *
>> **/
>> - public static final String STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION
>> = - "derby.storage.dataNotSyncedAtAllocation";
>> -
>> - /**
>> - * derby.storage.logNotSynced
>> - * <p>
>> - * When set, the store system will not force a sync() call on the
>> log at - * commit.
>> - * <p>
>> - * An internal debug system only flag. The recovery system will not
>> - * work properly if this flag is enabled, it is provided to do
>> performance
>> - * debugging to see whether the system is I/O bound based on log
>> file
>> - * synchronous I/O.
>> - * <p>
>> - *
>> - **/
>> - public static final String STORAGE_LOG_NOT_SYNCED = -
>> "derby.storage.logNotSynced";
>> -
>> + public static final String TESTMODE_NO_SYNC = +
>> "derby.system.testMode";
>> +
>> /**
>> * derby.storage.fileSyncTransactionLog
>> * <p>
>> Index: java/engine/org/apache/derby/loc/messages_en.properties
>> ===================================================================
>> --- java/engine/org/apache/derby/loc/messages_en.properties
>> (revision 165265)
>> +++ java/engine/org/apache/derby/loc/messages_en.properties
>> (working copy)
>> @@ -1150,7 +1150,10 @@
>> L016=cannot create a new log file {0}
>> L017=cannot create a new log file {0} due to {1}
>> L018=System may be in a inconsistent state, missing file {0}
>> +L020=WARNING: The database was previously booted with {0} set to
>> true. Note that this mode {0}=true does not guarantee recoverability \n
>> +L021=WARNING: The database was either previously booted or is
>> currently booted with {0} set to true. Note that this mode {0}=true
>> does not guarantee recoverability, and is probably what might have
>> caused this boot error \n
>>
>> +
>> # Class Manager
>> C000=Wrote class {0} to file {1}. Please provide support with the
>> file and the following exception information: {2}
>> C001=Class {0} has a unknown certificate type in jar {1}, expecting
>> X509 certificate.
>> @@ -1174,6 +1177,7 @@
>> D010=Backup aborted due to error
>> D011=removed old backup copy at {0}
>> D012=Backup completed, log instant at {0} \n
>> +D013=WARNING: {0} is set to true. In this mode, there is no guarantee
>> that the system will recover a system crash or JVM termination. Enable
>> this property only when there is no need for recoverability \n
>>
>> # Connectivity J004=database identity
>> Index:
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>>
>> ===================================================================
>> ---
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>> (revision 0)
>> +++
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>> (revision 0)
>> @@ -0,0 +1,202 @@
>> +/*
>> + + Derby - Class
>> org.apache.derbyTesting.functionTests.tests.store.TestNoSyncs
>> + + Copyright 2002, 2005 The Apache Software Foundation or its
>> licensors, as applicable.
>> + + Licensed under the Apache License, Version 2.0 (the "License");
>> + you may not use this file except in compliance with the License.
>> + You may obtain a copy of the License at
>> + + http://www.apache.org/licenses/LICENSE-2.0
>> + + Unless required by applicable law or agreed to in writing, software
>> + distributed under the License is distributed on an "AS IS" BASIS,
>> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>> implied.
>> + See the License for the specific language governing permissions and
>> + limitations under the License.
>> + + */
>> +
>> +package org.apache.derbyTesting.functionTests.tests.store;
>> +
>> +import java.sql.Connection;
>> +import java.sql.Statement;
>> +import java.sql.PreparedStatement;
>> +import java.io.*;
>> +/**
>> + * This program tests the system when the derby.system.testMode
>> property is enabled
>> + *
>> + * When the derby.system.testMode is set, the system will not do any
>> sync to the disk and
>> + * the recovery system will not work property.
>> + * It is provided for performance reasons and should ideally only be
>> used
>> + * when there is no requirement for the database to recover.
>> + * <p>
>> + * When set, the system will not do any syncs, the cases namely
>> + * - no sync of the log file at each commit
>> + * - no sync of the log file before data page is forced to disk
>> + * - no sync of page allocation when file is grown
>> + * - no sync of data writes during checkpoint
>> + * <p>
>> + * That means, when this property is set to true,
>> + * - a commit no longer guarantees that the transaction's modification
>> + * will survive a system crash or JVM termination
>> + * - the database may not recover successfully upon restart
>> + * - a near full disk at runtime may cause unexpected errors
>> + *
>> + * This program tests for
>> + * 1. enabling the derby.system.testMode is actually not doing the syncs
>> + * by timing inserts
>> + * 2. check if a warning message exists in derby.log
>> + * 3. read log.ctrl file and check if the flag is set or not
>> + *
>> + *
>> + * @author <a href="mailto:ksunithaghm@gmail.com">Sunitha
>> Kambhampati</a>
>> + * @version 1.0
>> + */
>> +public class TestNoSyncMode
>> +{
>> + public static void main(String[] args)
>> + {
>> + Connection conn = null;
>> + Statement s = null;
>> + PreparedStatement ps = null;
>> + try
>> + {
>> + // use the ij utility to read the property file and
>> + // make the initial connection.
>> + org.apache.derby.tools.ij.getPropertyArg(args);
>> + conn = org.apache.derby.tools.ij.startJBMS();
>> +
>> + s = conn.createStatement();
>> + s.execute("create table t1 (c1 int, c2 int)");
>> + s.close();
>> +
>> + // Test 1
>> + // this is a quick check incase someone breaks the
>> derby.system.testMode + long timeTaken =
>> doInsertsInAutoCommit(conn);
>> + conn.close();
>> +
>> + int approxUpperBound = 3000; // approximate upper bound
>> in millisecond
>> + if ( timeTaken > approxUpperBound )
>> + {
>> + report("FAIL -- derby.system.testMode mode seems to
>> be broken.");
>> + report(" Time to insert rows in test exceeded the
>> usual limit.");
>> + }
>> +
>> + // Test 2
>> + // Check if derby.log has the warning message
>> + report("Is warning message about derby.system.testMode
>> present in derby.log ="+ isMessageInDerbyLog());
>> + // Test 3
>> + // Check if marker is correctly written out to database
>> + markerInControlFile();
>> +
>> +
>> + }
>> + catch (Throwable e) {
>> + report("FAIL -- unexpected exception: "+e);
>> + e.printStackTrace();
>> + }
>> +
>> + }
>> +
>> +
>> + /**
>> + * Note doing inserts in autocommit mode is probably the worst
>> case scenario
>> + * in terms of performance as each commit will involve a
>> flush/sync to disk
>> + * but in case of the derby.system.testMode=true mode, the syncs
>> dont happen
>> + * This test case times the inserts and assumes that the inserts
>> on any system
>> + * will be less than three second for 500 inserts.
>> + * Note this upper bound on time is just an approximate
>> estimation + */
>> + public static long doInsertsInAutoCommit(Connection conn)
>> + throws Exception
>> + {
>> + PreparedStatement ps = conn.prepareStatement("insert into t1
>> values(?,?)");
>> + long count = 0;
>> +
>> + long start = System.currentTimeMillis();
>> +
>> + for ( int i = 0; i < 500; i++ )
>> + {
>> + ps.setInt(1,i);
>> + ps.setInt(2,i);
>> + count += ps.executeUpdate();
>> + }
>> +
>> + long end = System.currentTimeMillis();
>> + report("num successful inserts = "+count);
>> +
>> + return ( end - start);
>> + }
>> +
>> + /**
>> + * When derby.system.testMode is set, a warning message is
>> written out to derby.log
>> + * indicating that the property is set and that it does not
>> guarantee recoverability
>> + * This test tests if a message is written out to derby.log or
>> not + */
>> + public static boolean isMessageInDerbyLog()
>> + throws Exception
>> + {
>> + BufferedReader reader = null;
>> + File derbylog = null;
>> + try
>> + {
>> + String derbyHome = System.getProperty("derby.system.home");
>> + derbylog = new File(derbyHome,"derby.log");
>> + reader = new BufferedReader(new FileReader(derbylog));
>> +
>> + String line = null;
>> + while((line = reader.readLine())!= null)
>> + {
>> + if(line.indexOf("derby.system.testMode") != -1)
>> + return true;
>> +
>> + }
>> + return false;
>> + }
>> + finally
>> + {
>> + if (reader != null)
>> + {
>> + reader.close();
>> + }
>> + derbylog = null;
>> + }
>> + }
>> +
>> + /**
>> + * if derby.system.testMode is set, a marker is written out into
>> log control file
>> + * to recognize that the database was previously booted in this
>> mode + * Test if the marker byte is set correctly or not
>> + * See comments in org.apache.derby.impl.store.log.LogToFile for
>> IS_TESTMODE_NO_SYNC_FLAG
>> + */
>> + public static void markerInControlFile()
>> + throws Exception
>> + {
>> + RandomAccessFile controlFile = null;
>> + try
>> + {
>> + int testModeNoSyncMarkerPosition = 29;
>> + String derbyHome = System.getProperty("derby.system.home");
>> + controlFile = new
>> RandomAccessFile(derbyHome+"/wombat/log/log.ctrl","r");
>> + controlFile.seek(testModeNoSyncMarkerPosition);
>> + report("log.ctrl file has testMode NoSync marker value =
>> "+ controlFile.readByte());
>> + }
>> + finally
>> + {
>> + if(controlFile != null)
>> + controlFile.close();
>> + + }
>> + }
>> +
>> + public static void report(String msg)
>> + {
>> + System.out.println(msg);
>> + }
>> +
>> +}
>> +
>> +
>> +
>>
>> Property changes on:
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>>
>> ___________________________________________________________________
>> Name: svn:eol-style
>> + native
>>
>> Index:
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
>>
>> ===================================================================
>> ---
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
>> (revision 165265)
>> +++
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
>> (working copy)
>> @@ -23,6 +23,7 @@
>> TransactionTable.sql
>> TransactionTable_app.properties
>> TransactionTable_derby.properties
>> +TestNoSyncMode_derby.properties
>> access.sql
>> access_app.properties
>> access_derby.properties
>> Index:
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>>
>> ===================================================================
>> ---
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>> (revision 0)
>> +++
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>> (revision 0)
>> @@ -0,0 +1 @@
>> +derby.system.testMode=true
>>
>> Property changes on:
>> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>>
>> ___________________________________________________________________
>> Name: svn:eol-style
>> + native
>>
>> Index:
>> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>>
>> ===================================================================
>> ---
>> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>> (revision 0)
>> +++
>> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>> (revision 0)
>> @@ -0,0 +1,3 @@
>> +num successful inserts = 500
>> +Is warning message about derby.system.testMode present in derby.log
>> =true
>> +log.ctrl file has testMode NoSync marker value = 1
>> Index:
>> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
>>
>> ===================================================================
>> ---
>> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
>> (revision 165265)
>> +++
>> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
>> (working copy)
>> @@ -4,3 +4,4 @@
>> store/longColumn.sql
>> store/madhare.sql
>> store/streamingColumn.java
>> +store/TestNoSyncMode.java
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by David Van Couvering <Da...@Sun.COM>.
Hi, Sunitha. Thanks for your work on this. My comment is more a
"marketing" comment than a technical one. I disagree that this is
useful only for testing and development. As I mentioned in previous
emails, there are a number of customers who may find this very useful
indeed, who are willing to trade off 100% guarantee of all transactions
being available on recovery for significant increases in performance.
I wouldn't get into this debate were it not for the fact that the
property you have created is called "testMode." I would much rather
have it not imply it's only for testing, with a name like "delayedWrite"
or "relaxedDurability" or some such.
Thanks,
David
Sunitha Kambhampati wrote:
> A little background: Sometime earlier on the list, Dan posted a fix to
> make derby go faster with relaxed durability with some flags. The post
> is at
> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>
> This mode is very useful for unit testing or at development time when
> recoverability is not required.
> Basically in this mode, syncs are disabled for logs, data writes at
> checkpoint, page allocation when file is grown; - what this means is
> that data is not flushed all the way to the disk and in most cases i/o
> cost is not involved. Note, code already exists in Derby to do this.
> So for Derby 218, This patch addresses the following requirements: 1)
> Have a single property to enable this relaxed durability mode, so it is
> easy for users to enable it.
> 2) Print message to derby.log that this mode is enabled
> 3) A way to report boot errors that may be because of this option being
> enabled. What this maps to is - have a marker to recognize that database
> was booted in this mode, and then on subsequent boot; if errors happen
> during recovery - report a message that it could have happened because
> of this mode being set.
>
> Changes are not much. svn stat
> M java\engine\org\apache\derby\impl\store\raw\log\LogToFile.java
> M
> java\engine\org\apache\derby\impl\store\raw\data\BaseDataFileFactory.java
> M java\engine\org\apache\derby\impl\store\raw\data\RAFContainer.java
> M java\engine\org\apache\derby\iapi\reference\MessageId.java
> M java\engine\org\apache\derby\iapi\reference\Property.java
> M java\engine\org\apache\derby\loc\messages_en.properties
> A
> java\testing\org\apache\derbyTesting\functionTests\tests\store\TestNoSyncMode.java
>
> M
> java\testing\org\apache\derbyTesting\functionTests\tests\store\copyfiles.ant
>
> A
> java\testing\org\apache\derbyTesting\functionTests\tests\store\TestNoSyncMode_derby.properties
>
> A
> java\testing\org\apache\derbyTesting\functionTests\master\TestNoSyncMode.out
>
> M
> java\testing\org\apache\derbyTesting\functionTests\suites\storemats.runall
>
> Since this is a longish email , for those who may not read the rest of
> it, here are the testing results
>
> Testing results:
> - I ran derbyall with 1.4.2 jvm and all tests passed. - I ran the
> storeall suite separately both with setting the derby.system.testMode
> property to true and without it. with this property set, the
> storeall suite ran about 2 times as fast.
> -------------------------------
>
> Below I explain how the patch addresses the above requirements and try
> to provide details on how I went about making those changes
>
> 0) Note
> 1) A single property has been added to enable this relaxed durability
> option. The property name is derby.system.testMode and takes in value
> true or false. By default it is false. It can be set as a command line
> option to the JVM when starting the application or within the
> application or in the derby.properites file. Property is loaded at boot
> time, so for it to have an effect you need to enable it at boot time.
> More comments added in code itself. see variable TESTMODE_NO_SYNC =
> "derby.system.testMode"; in Property.java.
>
> (In this patch, I have used 'no_sync' as suffix in variable names
> because I think with respect to store - that is what this mode is all
> about - disabling syncs for the cases already mentioned earlier in this
> mail)
>
> I chose the property name derby.system.testMode for this
> - represents a higher concept as to when one would use relaxed
> durability (no sync) option.
> - mostly it should be enabled only when data is not important and
> ideally maybe for testing and development purposes,
> - also with the hope that the word 'testMode' would prompt users to
> look this property up before using it in a production like environment
> where it may not necessarily be appropriate.
>
> Code changes for this:
> - Added this new property derby.system.testMode in
> java\engine\org\apache\derby\iapi\reference\Property.java
>
> - Removed the following properties from Property.java as they are no
> longer required.
> derby.storage.dataNotSyncedAtCheckPoint=true ( I'll refer to this
> as DNSAC in notes below)
> derby.storage.dataNotSyncedAtAllocation=true ( I'll refer to
> this as DNSAA in notes below)
> derby.storage.logNotSynced=true (I'll refer to this as LNS
> in notes below)
>
> - Previously code existed for enabling the DNSAC, DNSAA and LNS options
> conditional on Performance.MEASURE
>
> So how it works is , the 2 variables in BaseDataFileFactory.java are
> used to control if syncs happen or not for data pages at allocation and
> at checkpoint.
> dataNotSyncedAtAllocation dataNotSyncedAtCheckpoint
>
> And in java/engine/org/apache/derby/impl/store/raw/log/LogToFile, the
> logNotSynced variable is used to control if syncs happen for the logs
> are not.
>
> These variables are enabled (set to true) if Performance.MEASURE is set
> to true, and if the DNSAC, and DSNAA propertie are enabled.
>
> So all that is required now is
> - remove conditional on Performance.MEASURE in these cases, instead use
> the derby.system.testMode property to enable them . This happens in the
> boot methods
> - make sure to remove any conditionals on Performance.MEASURE that is
> used to disable syncs but instead control it by the variables mentioned
> above.. ie e.g. dataNotSyncedAtAllocation in BaseDataFileFactory.java ...
> - remove reading of the DNSAC, DNSAA,LNS property as they are not needed
> anymore
>
> Changes were needed to following files - i)
> java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
> (check boot method)
> ii) java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
> iii) java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
> (check boot method).
>
> 2) Write to the derby.log a warning message
>
> Needed to add a new message.
> Messages need to be translated, so I made the following changes
>
> i) added a variable in
> java/engine/org/apache/derby/iapi/reference/MessageId.java to represent
> this new message.
> String STORE_TESTMODE_NO_SYNC = "D013";
>
> ii) Message content added to
> java/engine/org/apache/derby/loc/messages_en.properties
> D013=WARNING: {0} is set to true. In this mode, there is no guarantee
> that the system will recover a system crash or JVM termination. Enable
> this property only when there is no need for recoverability \n
>
> iii) In the boot process, rawstore boot calls logfactory boot, so the
> first time the derby.system.testMode property is read, it is in
> rawstore, so added code to print the warning message in
> BaseDataFileFactory.boot(..)
>
>
> 3) A way to report boot errors that may be because of this option being
> enabled. What this maps to is - have a marker to recognize that database
> was booted in this mode, and then on subsequent boot if errors happen
> during recovery report a message that it could have happened because of
> this mode being set.
>
> - To write a marker out , log.ctrl file is used, it has a few spare
> bytes so no major changes needed here. ( ie no disk format changes.... )
> Check the method readControlFile in
> java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
>
> - Used the first spare byte available in log control file which will be
> used to store information about if derby.system.testMode is set or not.
> Added variable TESTMODE_NO_SYNC_FLAG_OFFSET to represent this offset in
> LogToFile.java
>
> - The value written out if this property is enabled is
> TESTMODE_NO_SYNC_TRUE = 0x1 else a 0 is written out. ( I didnt like to
> put the 0 but wasnt feeling too strong to adding a new static byte
> variable either.. and as rest of the code around it in writeControlFile
> seems to use 0 as is , I just followed the same approach).
>
> - Change made to readControlFile to read in the value for the testmode
> case when Logfactory is booted, the flag is read and value stored
> in variable called wasDBInTestModeNoSync. This variable keeps track of
> if database was previously booted in the derby.system.testMode or not.
> Comes in use for error reporting.
>
> - Also added a message to report to the derby.log incase database was
> previously booted with derby.system.testMode set to true. Change to
> messages_en.properties and MessageId.java.
> L020=WARNING: The database was previously booted with {0} set to true.
> Note that this mode {0}=true does not guarantee recoverability \n
>
> little on the flow with respect to writeControlFile .. if you look at
> the code in LogToFile for boot and recover, writeControlFile is called a
> couple of times.. to read the checkpoint instant etc..
> - For my changes, I am just copy/paste the comments from
> writeControlFile(...) , Note case4 below .. which is the interesting one.
>
> // A spare byte at offset TESTMODE_NO_SYNC_FLAG_OFFSET
> // is used to write out if database was in
> derby.system.testMode=true mode
> // or not.
> // This byte will have one of the two values
> // - TESTMODE_NO_SYNC_TRUE to represent database was booted
> // in this mode
> // - 0 to represent database was not booted in this mode
> // // The sole purpose of this flag in control file is to
> help
> // identify any recovery problems that might happen as a result
> of this
> // mode being set.
> //
> // Possible scenarios. In table below, cases are listed giving
> // the value of derby.system.testMode if it was enabled or not at
> boot time
> // ---------------------------------------------------------------
> // Case Previous Current Action , what should
> the flag be set to in log.ctrl
> // Boot Boot file
> // --------------------------------------------------------------
> // 1 - true write
> TESTMODE_NO_SYNC_TRUE
> // 2 - false write 0
> // 3 false false write 0
> // 4 true false write
> TESTMODE_NO_SYNC_TRUE
> // 5 true true write
> TESTMODE_NO_SYNC_TRUE
> //
> // Case 4 is the interesting case here.
> // one cannot write out the derby.system.testMode is disabled
> just yet
> // because it is possible that the database recovery might fail
> and on subsequent
> // restarts this state would be lost. So only when recovery is
> successful, will
> // we update the flag in the log control file to indicate that
> the derby.system.testMode
> // is not enabled. (This will happen at the end of recovery ,
> see recover method)
> //
> // Case 1, 2 is when database is created fresh with this property
> enabled.
> //
> // wasDBInTestModeNoSync has information if database was
> previously booted
> // in derby.system.testMode=true mode
>
> To handle case 4, changes went into recover () method , if database
> recovery is successful only then we update the flag in the control file
> to say database is not booted with this property enabled. Since there
> was no method available to update the log control file, added a new
> method updateTestModeFlagInCtrlFile(byte value) to do that.
>
> So now that changes are done to write the marker to the control file and
> to read it, it is necessary to take care of case when error happens.
>
> - added a new message to report that cause of an error could be related
> to this property being set
> added a new variable in MessageId.LOG_TESTMODE_NO_SYNC_ERR in
> java/engine/org/apache/derby/iapi/reference/MessageId.java
> and the message to java/engine/org/apache/derby/loc/messages_en.properties
> L021=WARNING: The database was either previously booted or is currently
> booted with {0} set to true. Note that this mode {0}=true does not
> guarantee recoverability, and is probably what might have caused this
> boot error \n
> - added MessageId.LOG_TESTMODE_NO_SYNC_ERR in
> java/engine/org/apache/derby/iapi/reference/MessageId.java
>
> Added a new method logErrMsgForTestModeNoSync() in LogToFile.java to
> print out this message if any error happens when database is in the
> influence of this property.
>
> In deciding what the best place would be to call the
> logErrMsgForTestModeNoSync, I debated between adding it in markCorrupt()
> versus logErrMsg(..). It seemed like if error happened during boot -
> the flow was to call markCorrupt which would call logErrMsg. Some error
> messages seem to call logErrMsg(..) directly. So I picked the
> logErrMsg as it covered most of the errors thrown during boot/recovery
> that would be related to something with this property being set.
> -------------------------------------------
>
> TESTING
>
> 1) I added one new java file per the derby test harness, to test the
> following
> - check if the property is enabled correctly by timing some inserts
> into a table.
> - check if the correct flag (TESTMODE_NO_SYNC_TRUE) is written out
> into the log.ctrl file
> - check if the derby.log has the warning message.
>
> Changes include
> i)Added new test to
> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
>
> ii)Added
> java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
>
>
> TestNoSyncMode_derby.properties has
> derby.system.testMode=true
>
> This property file is needed so when test is run it picks up this property.
>
> iii)The TestNoSyncMode_derby.properties is added to copyfiles.ant so it
> will be copied over when compiling derby tests.
>
> iv) To enable this new test as part of the store suite, I modified the
> java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
> added store/TestNoSyncMode.java
>
> v) To get my correct output file, first i just put an initial empty file
> in
> java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
>
>
> Ran the test after compiling source; java
> org.apache.derbyTesting.functionTests.harness.RunTest
> store/TestNoSyncMode.java
> Then I updated the out file in the master directory, after checking if
> the TestNoSyncMode.out file was correct.
>
> 2) For the error messages on a boot error, it is difficult to put it in
> a test, so I checked this in the debugger and it works ok.
>
> Meanwhile, Suresh Thalamati posted on the list that he is working on a
> corruptible storage factory, once that is there - I am hoping I could
> use that to have a test to check the error messages for boot errors.
>
> As far as I can tell, this does not affect upgrade and such since we are
> not changing the disk format etc.. ..There is one spare byte in
> log.ctrl file that is being used now as a result of this change and
> this byte value should not have been used to represent anything useful
> by any earlier version
>
> Testing results (already mentioned in the beginning of this email).
>
> Please give your comments.
> Thanks,
> Sunitha.
>
>
> ------------------------------------------------------------------------
>
> Index: java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
> ===================================================================
> --- java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java (revision 165265)
> +++ java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java (working copy)
> @@ -265,7 +265,38 @@
>
> /* Log Control file flags. */
> private static final byte IS_BETA_FLAG = 0x1;
> -
> +
> + /**
> + * When the derby.system.testMode property is enabled, the store
> + * system will not force sync calls in the following cases
> + * - for the log file at each commit
> + * - for the log file before data page is forced to disk
> + * - for page allocation when file is grown
> + * - for data writes during checkpoint
> + * This means the recovery system may not work properly
> + * In order that we recognize this case that the database was previously
> + * booted in this mode, this value is written out
> + * into the log control file. This will help prevent us from
> + * wasting time to resolve issues in such cases.
> + * @see org.apache.derby.iapi.reference.Property#TESTMODE_NO_SYNC
> + */
> + private static final byte TESTMODE_NO_SYNC_TRUE = 0x1;
> +
> + /**
> + * A byte in the log control file is used to store information
> + * about if the database is booted in derby.system.testMode mode
> + * The first available spare byte that is available for this purpose is
> + * after 5 ints ( 4bytes each), a long ( 8 bytes) and 1 byte in the log control
> + * file. Hence the offset is calculated as follows
> + */
> + private static final int TESTMODE_NO_SYNC_FLAG_OFFSET = 5*4 + 8 + 1;
> +
> + /**
> + * keeps track of if the database was booted previously with
> + * derby.system.testMode=true
> + */
> + private static boolean wasDBInTestModeNoSync = false;
> +
> /* to err on the conservative side, unless otherwise set, assume log
> * archive is ON
> */
> @@ -362,7 +393,7 @@
> // log goes to the log subdirectory underneath the data directory
> String logDevice;
>
> - // debug only flag - disable syncing of log file for debugging performance.
> + // disable syncing of log file when running in derby.system.testMode enabled
> private boolean logNotSynced = false;
>
> private boolean logArchived = false;
> @@ -403,6 +434,7 @@
>
> private CRC32 checksum = new CRC32(); // holder for the checksum
>
> + protected static int CHECKSUM_SIZE = 8; // checksum size in bytes
>
>
> /**
> @@ -1194,8 +1226,28 @@
> tf.resetTranId();
> }
>
> - // done with recovery
> -
> + // If we have reached here successfully, that means recovery
> + // was successful
> +
> + // Now that database has recovered successfully and if it
> + // is booted with derby.system.testMode=false mode, there is no
> + // need to store information that database was booted previously in
> + // derby.system.testMode=true mode.
> + // It is safe to update the marker in log.ctrl file to say
> + // that the derby.system.testMode in not being used
> +
> + // Need to write to the log.ctrl file as well as the log mirror file
> + if( wasDBInTestModeNoSync && !logNotSynced )
> + {
> + // write to log control file and the mirror file that the testmode
> + // is not used now
> + if(!updateTestModeFlagInCtrlFile((byte)0))
> + throw StandardException.newException(
> + SQLState.LOG_CONTROL_FILE, getControlFileName());
> +
> + wasDBInTestModeNoSync = false;
> + }
> +
> /////////////////////////////////////////////////////////////
> // setup checktpoint daemon
> /////////////////////////////////////////////////////////////
> @@ -1207,6 +1259,99 @@
> }
> }
>
> + /**
> + * Update the flag that represents whether
> + * derby.system.testMode is enabled or not in both the log control file
> + * as well as the mirror control file
> + * <BR>
> + * Basically, Read the control file,
> + * update the flag to the new passed in value
> + * recalculate the checksum and write it out to the log control file
> + * <P> MT- synchronized by caller
> + * @param value to set
> + * @return false if the update didnt happen successfully, else true
> + * @throws IOException
> + * @throws StandardException
> + * @see #readControlFile
> + * @see #writeControlFile(StorageFile, long)
> + */
> + private boolean updateTestModeFlagInCtrlFile(byte value)
> + {
> + StorageRandomAccessFile logControlFile = null;
> + byte barray[] = null;
> + StorageFile ctrlFile = null;
> +
> + try
> + {
> + ctrlFile = getControlFileName();
> + logControlFile = privRandomAccessFile(ctrlFile, "rw");
> + if (!privCanWrite(ctrlFile))
> + return false;
> +
> + // retrieve all except the checksum bytes
> + barray = new byte[(int) logControlFile.length() - CHECKSUM_SIZE];
> + logControlFile.readFully(barray);
> +
> + if (SanityManager.DEBUG)
> + {
> + if (SanityManager.DEBUG_ON(DBG_FLAG))
> + {
> + SanityManager.DEBUG(DBG_FLAG,
> + "Updating derby.system.testMode marker written out"+
> + "to log control file: prev value = " +
> + barray[TESTMODE_NO_SYNC_FLAG_OFFSET] + " to "+ value);
> + }
> + }
> + // update the byte at position that represents whether
> + // derby.system.testMode was used
> + barray[TESTMODE_NO_SYNC_FLAG_OFFSET] = value;
> +
> + // write back into file the updated value and also compute
> + // the newchecksum and write it to file
> + logControlFile.seek(0);
> + logControlFile.write(barray);
> + checksum.reset();
> + checksum.update(barray, 0, barray.length);
> + logControlFile.writeLong(checksum.getValue());
> + syncFile(logControlFile);
> + logControlFile.close();
> +
> + // write the same data to mirror control file
> + ctrlFile = getMirrorControlFileName();
> + logControlFile =
> + privRandomAccessFile(ctrlFile, "rw");
> + if (!privCanWrite(ctrlFile))
> + return false;
> + logControlFile.seek(0);
> + logControlFile.write(barray);
> + logControlFile.writeLong(checksum.getValue());
> + syncFile(logControlFile);
> + }
> + catch(IOException ioe)
> + {
> + logControlFile = null;
> + return false;
> + }
> + catch(StandardException se)
> + {
> + logControlFile = null;
> + return false;
> + }
> + finally
> + {
> + try
> + {
> + if (logControlFile != null)
> + logControlFile.close();
> + }
> + catch(IOException ioe2)
> + {
> + logControlFile = null;
> + return false;
> + }
> + }
> + return true;
> + }
> /**
> Checkpoint the rawStore.
>
> @@ -2142,10 +2287,61 @@
>
> //
> // write some spare bytes after 2.0 we have 3 + 2(8) spare bytes.
> + // now with v10.1.0.0 we have 2 +2(8) spare bytes as one of the spare
> + // byte is used as a marker to write out if system is runinng
> + // in derby.system.testMode=true or not.
> +
> long spare = 0;
> +
> + // A spare byte at offset TESTMODE_NO_SYNC_FLAG_OFFSET
> + // is used to write out if database was in derby.system.testMode=true mode
> + // or not.
> + // This byte will have one of the two values
> + // - TESTMODE_NO_SYNC_TRUE to represent database was booted
> + // in this mode
> + // - 0 to represent database was not booted in this mode
> + //
> + // The sole purpose of this flag in control file is to help
> + // identify any recovery problems that might happen as a result of this
> + // mode being set.
> + //
> + // Possible scenarios. In table below, cases are listed giving
> + // the value of derby.system.testMode if it was enabled or not at boot time
> + // ---------------------------------------------------------------
> + // Case Previous Current Action , what should the flag be set to in log.ctrl
> + // Boot Boot file
> + // --------------------------------------------------------------
> + // 1 - true write TESTMODE_NO_SYNC_TRUE
> + // 2 - false write 0
> + // 3 false false write 0
> + // 4 true false write TESTMODE_NO_SYNC_TRUE
> + // 5 true true write TESTMODE_NO_SYNC_TRUE
> + //
> + // Case 4 is the interesting case here.
> + // one cannot write out the derby.system.testMode is disabled just yet
> + // because it is possible that the database recovery might fail and on subsequent
> + // restarts this state would be lost. So only when recovery is successful, will
> + // we update the flag in the log control file to indicate that the derby.system.testMode
> + // is not enabled. (This will happen at the end of recovery , see recover method)
> + //
> + // Case 1, 2 is when database is created fresh with this property enabled.
> + //
> + // wasDBInTestModeNoSync has information if database was previously booted
> + // in derby.system.testMode=true mode
> + if( !wasDBInTestModeNoSync ) // derby.system.testMode=false
> + {
> + // in this case, no need to write out any special marker
> + // for derby.system.testMode=false case.
> + if(!logNotSynced)
> + daos.writeByte(0);
> + else
> + daos.writeByte(TESTMODE_NO_SYNC_TRUE);
> + }
> + else
> + daos.writeByte(TESTMODE_NO_SYNC_TRUE);
> +
> daos.writeByte(0);
> daos.writeByte(0);
> - daos.writeByte(0);
> daos.writeLong(spare);
> daos.flush();
> // write the checksum for the control data written
> @@ -2281,7 +2477,24 @@
> onDiskMinorVersion = dais.readInt();
> int dbBuildNumber = dais.readInt();
> int flags = dais.readByte();
> -
> +
> + // check if the database was running previously with
> + // derby.system.testMode=true mode
> + // if database was running previously in derby.system.testMode=true
> + // and if on a restart - recovery fails we want to be able
> + // to report that the boot error could have happened
> + // because of this property
> + wasDBInTestModeNoSync =(dais.readByte() & TESTMODE_NO_SYNC_TRUE) != 0;
> +
> + if (SanityManager.DEBUG)
> + {
> + if (SanityManager.DEBUG_ON(LogToFile.DBG_FLAG))
> + SanityManager.DEBUG(LogToFile.DBG_FLAG,
> + "log control file, was derby.system.testMode enabled = " +
> + wasDBInTestModeNoSync);
> + }
> +
> +
> onDiskBeta = (flags & IS_BETA_FLAG) != 0;
>
> if (onDiskBeta)
> @@ -2794,19 +3007,15 @@
> isWriteSynced = false;
> }
>
> - if (Performance.MEASURE)
> + // if system is running with derby.system.testMode enabled
> + // log records and log file are not synced, so
> + // set flag to disable log syncs
> + if (PropertyUtil.getSystemBoolean(Property.TESTMODE_NO_SYNC))
> {
> - // debug only flag - disable syncing of log.
> - logNotSynced =
> - PropertyUtil.getSystemBoolean(Property.STORAGE_LOG_NOT_SYNCED);
> -
> - if (logNotSynced)
> - {
> - Monitor.logMessage("logNotSynced = true");
> - //if log is Not being synced;files should not be open in write sync mode
> - isWriteSynced = false;
> - }
> -
> + // disable syncing of log.
> + logNotSynced = true;
> + //if log is Not being synced;files should not be open in write sync mode
> + isWriteSynced = false;
> }
>
> // try to access the log
> @@ -2830,6 +3039,18 @@
> if (privExists(logControlFileName))
> {
> checkpointInstant = readControlFile(logControlFileName, startParams);
> + // in case system was running previously with derby.system.testMode=true
> + // then print a message to the derby log
> + if(wasDBInTestModeNoSync)
> + {
> + // print message stating that the database was
> + // previously running with derby.system.testMode=true
> + // mode
> + Monitor.logMessage(MessageService.getTextMessage(
> + MessageId.LOG_WAS_IN_TESTMODE_NO_SYNC,
> + Property.TESTMODE_NO_SYNC));
> + }
> +
> if (checkpointInstant == LogCounter.INVALID_LOG_INSTANT &&
> getMirrorControlFileName().exists())
> checkpointInstant =
> @@ -2879,8 +3100,9 @@
> // blow away the log file if possible
> if (!privDelete(logFile) && logFileNumber == 1)
> {
> + logErrMsgForTestModeNoSync();
> throw StandardException.newException(
> - SQLState.LOG_INCOMPATIBLE_FORMAT, dataDirectory);
> + SQLState.LOG_INCOMPATIBLE_FORMAT,dataDirectory);
> }
>
> // If logFileNumber > 1, we are not going to write that file just
> @@ -2913,6 +3135,7 @@
>
> if (!privDelete(logFile))
> {
> + logErrMsgForTestModeNoSync();
> throw StandardException.newException(
> SQLState.LOG_INCOMPATIBLE_FORMAT,
> dataDirectory);
> @@ -3584,15 +3807,8 @@
> }
> else
> {
> - if (Performance.MEASURE)
> - {
> - if (!logNotSynced)
> - logOut.syncLogAccessFile();
> - }
> - else
> - {
> - logOut.syncLogAccessFile();
> - }
> + if (!logNotSynced)
> + logOut.syncLogAccessFile();
> }
>
> syncSuceed = true;
> @@ -3925,6 +4141,7 @@
> */
> protected void logErrMsg(String msg)
> {
> + logErrMsgForTestModeNoSync();
> Monitor.logTextMessage(MessageId.LOG_BEGIN_ERROR);
> Monitor.logMessage(msg);
> Monitor.logTextMessage(MessageId.LOG_END_ERROR);
> @@ -3936,6 +4153,7 @@
> */
> protected void logErrMsg(Throwable t)
> {
> + logErrMsgForTestModeNoSync();
> if (corrupt != null)
> {
> Monitor.logTextMessage(MessageId.LOG_BEGIN_CORRUPT_STACK);
> @@ -3951,6 +4169,22 @@
> }
> }
>
> + /**
> + * In case of boot errors, and if database is either booted
> + * with derby.system.testMode being set or was previously booted in this
> + * mode, mention in the error message that the error is probably
> + * because the derby.system.testMode was set.
> + * Dont want to waste time to resolve issues in such
> + * cases
> + * <p>
> + * MT - not needed, informational only
> + */
> + protected void logErrMsgForTestModeNoSync()
> + {
> + if(logNotSynced || wasDBInTestModeNoSync)
> + Monitor.logTextMessage(MessageId.LOG_TESTMODE_NO_SYNC_ERR);
> + }
> +
> private void printErrorStack(Throwable t)
> {
> Monitor.logMessage("-------------------------\n");
> Index: java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
> ===================================================================
> --- java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java (revision 165265)
> +++ java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java (working copy)
> @@ -179,11 +179,11 @@
> private static final String LINE =
> "----------------------------------------------------------------";
>
> - // debug only flag - disable syncing of data during page allocation.
> - boolean dataNotSyncedAtAllocation;
> + // disable syncing of data during page allocation.
> + boolean dataNotSyncedAtAllocation = false;
>
> - // debug only flag - disable syncing of data during checkpoint.
> - boolean dataNotSyncedAtCheckpoint;
> + // disable syncing of data during checkpoint.
> + boolean dataNotSyncedAtCheckpoint = false;
>
> // these fields can be accessed directly by subclasses if it needs a
> // different set of actions
> @@ -375,29 +375,24 @@
>
> droppedTableStubInfo = new Hashtable();
>
> - if (Performance.MEASURE)
> + /**
> + * If derby.system.testMode=true then set flags to
> + * disable sync of data pages at allocation when file is grown,
> + * disable sync of data writes during checkpoint
> + */
> + if (PropertyUtil.getSystemBoolean(Property.TESTMODE_NO_SYNC))
> {
> - // debug only flag - disable syncing of data during checkpoint.
> - dataNotSyncedAtCheckpoint =
> - PropertyUtil.getSystemBoolean(
> - Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT);
> + // - disable syncing of data during checkpoint.
> + dataNotSyncedAtCheckpoint = true;
>
> - // debug only flag - disable syncing of data during page allocation.
> - dataNotSyncedAtAllocation =
> - PropertyUtil.getSystemBoolean(
> - Property.STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION);
> -
> - if (dataNotSyncedAtCheckpoint)
> - Monitor.logMessage(
> - "Warning: " +
> - Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT +
> - "set to true.");
> -
> - if (dataNotSyncedAtAllocation)
> - Monitor.logMessage(
> - "Warning: " +
> - Property.STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION +
> - "set to true.");
> + // - disable syncing of data during page allocation.
> + dataNotSyncedAtAllocation = true;
> +
> + // log message stating that derby.system.testMode
> + // has been enabled.
> + Monitor.logMessage(MessageService.getTextMessage(
> + MessageId.STORE_TESTMODE_NO_SYNC,
> + Property.TESTMODE_NO_SYNC));
> }
>
> fileHandler = new RFResource( this);
> Index: java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java
> ===================================================================
> --- java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java (revision 165265)
> +++ java/engine/org/apache/derby/impl/store/raw/data/RAFContainer.java (working copy)
> @@ -325,15 +325,8 @@
> dataFactory.writeInProgress();
> try
> {
> - if (Performance.MEASURE)
> - {
> - if (!dataFactory.dataNotSyncedAtAllocation)
> - fileData.sync( false);
> - }
> - else
> - {
> + if (!dataFactory.dataNotSyncedAtAllocation)
> fileData.sync( false);
> - }
> }
> finally
> {
> @@ -504,16 +497,9 @@
> dataFactory.writeInProgress();
> inwrite = true;
>
> - if (Performance.MEASURE)
> - {
> - if (!dataFactory.dataNotSyncedAtAllocation)
> - fileData.sync( false);
> - }
> - else
> - {
> + if (!dataFactory.dataNotSyncedAtAllocation)
> fileData.sync( false);
> - }
> - }
> + }
> catch (IOException ioe)
> {
> // The disk may have run out of space.
> @@ -629,15 +615,9 @@
> dataFactory.writeInProgress();
> try
> {
> - if (Performance.MEASURE)
> - {
> - if (!dataFactory.dataNotSyncedAtCheckpoint)
> - file.sync( false);
> - }
> - else
> - {
> - file.sync( false);
> - }
> + if (!dataFactory.dataNotSyncedAtCheckpoint)
> + file.sync( false);
> +
> }
> finally
> {
> Index: java/engine/org/apache/derby/iapi/reference/MessageId.java
> ===================================================================
> --- java/engine/org/apache/derby/iapi/reference/MessageId.java (revision 165265)
> +++ java/engine/org/apache/derby/iapi/reference/MessageId.java (working copy)
> @@ -58,8 +58,10 @@
> String LOG_CANNOT_CREATE_NEW_DUETO = "L017";
> String LOG_MAYBE_INCONSISTENT = "L018";
> String LOG_TRANS_LOG_SCAN = "L019";
> + String LOG_WAS_IN_TESTMODE_NO_SYNC = "L020"; // system was running in derby.system.testMode set
> + String LOG_TESTMODE_NO_SYNC_ERR = "L021"; // hint that error could be because
> + // derby.system.testMode was set
>
> -
> /*
> * Raw Store data
> */
> @@ -75,6 +77,7 @@
> String STORE_BACKUP_ABORTED = "D010";
> String STORE_REMOVED_BACKUP = "D011";
> String STORE_BACKUP_COMPLETED = "D012";
> + String STORE_TESTMODE_NO_SYNC = "D013"; // for derby.system.testMode is set
>
>
> /*
> Index: java/engine/org/apache/derby/iapi/reference/Property.java
> ===================================================================
> --- java/engine/org/apache/derby/iapi/reference/Property.java (revision 165265)
> +++ java/engine/org/apache/derby/iapi/reference/Property.java (working copy)
> @@ -368,55 +368,47 @@
> <P>
> */
> String STORAGE_TEMP_DIRECTORY = "derby.storage.tempDirectory";
> -
> +
> /**
> - * derby.storage.dataNotSyncedAtCheckPoint
> + * derby.system.testMode
> * <p>
> - * When set, the store system will not force a sync() call on the
> - * containers during a checkpoint.
> + * When set, the store system will not force sync calls in the following
> + * cases
> + * - for the log file at each commit
> + * - for the log file before data page is forced to disk
> + * - for page allocation when file is grown
> + * - for data writes during checkpoint
> * <p>
> - * An internal debug system only flag. The recovery system will not
> - * work properly if this flag is enabled, it is provided to do performance
> - * debugging to see whether the system is I/O bound based on checkpoint
> - * synchronous I/O.
> + * That means, when this property is set to true
> + * - a commit no longer guarantees that the transaction's modification
> + * will survive a system crash or JVM termination
> + * - the database may not recover successfully upon restart
> + * - a near full disk at runtime may cause unexpected errors
> * <p>
> - *
> - **/
> - public static final String STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT =
> - "derby.storage.dataNotSyncedAtCheckPoint";
> -
> - /**
> - * derby.storage.dataNotSyncedAtAllocation
> + * This property is provided for performance reasons and should ideally
> + * only be used when there is no requirement for the database to recover.
> + * <BR>
> + * One sample use would be to enable this property when using Derby as a test
> + * database, where recoverability is not a concern but performance is important.
> + * <BR>
> + * Default value is false
> + * <BR>
> + * Valid Values
> + * Valid values are true or false
> + * <BR>
> + * Example
> + * derby.system.testMode=true
> + * One can set this as a command line option to the JVM when starting the
> + * application or in the derby.properties file
> + * <BR>
> + * This property is static; if you change it while Derby is running,
> + * the change does not take effect until you reboot.
> * <p>
> - * When set, the store system will not force a sync() call on the
> - * containers when pages are allocated.
> - * <p>
> - * An internal debug system only flag. The recovery system will not
> - * work properly if this flag is enabled, it is provided to do performance
> - * debugging to see whether the system is I/O bound based on page allocation
> - * synchronous I/O.
> - * <p>
> *
> **/
> - public static final String STORAGE_DATA_NOT_SYNCED_AT_ALLOCATION =
> - "derby.storage.dataNotSyncedAtAllocation";
> -
> - /**
> - * derby.storage.logNotSynced
> - * <p>
> - * When set, the store system will not force a sync() call on the log at
> - * commit.
> - * <p>
> - * An internal debug system only flag. The recovery system will not
> - * work properly if this flag is enabled, it is provided to do performance
> - * debugging to see whether the system is I/O bound based on log file
> - * synchronous I/O.
> - * <p>
> - *
> - **/
> - public static final String STORAGE_LOG_NOT_SYNCED =
> - "derby.storage.logNotSynced";
> -
> + public static final String TESTMODE_NO_SYNC =
> + "derby.system.testMode";
> +
> /**
> * derby.storage.fileSyncTransactionLog
> * <p>
> Index: java/engine/org/apache/derby/loc/messages_en.properties
> ===================================================================
> --- java/engine/org/apache/derby/loc/messages_en.properties (revision 165265)
> +++ java/engine/org/apache/derby/loc/messages_en.properties (working copy)
> @@ -1150,7 +1150,10 @@
> L016=cannot create a new log file {0}
> L017=cannot create a new log file {0} due to {1}
> L018=System may be in a inconsistent state, missing file {0}
> +L020=WARNING: The database was previously booted with {0} set to true. Note that this mode {0}=true does not guarantee recoverability \n
> +L021=WARNING: The database was either previously booted or is currently booted with {0} set to true. Note that this mode {0}=true does not guarantee recoverability, and is probably what might have caused this boot error \n
>
> +
> # Class Manager
> C000=Wrote class {0} to file {1}. Please provide support with the file and the following exception information: {2}
> C001=Class {0} has a unknown certificate type in jar {1}, expecting X509 certificate.
> @@ -1174,6 +1177,7 @@
> D010=Backup aborted due to error
> D011=removed old backup copy at {0}
> D012=Backup completed, log instant at {0} \n
> +D013=WARNING: {0} is set to true. In this mode, there is no guarantee that the system will recover a system crash or JVM termination. Enable this property only when there is no need for recoverability \n
>
> # Connectivity
> J004=database identity
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java (revision 0)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java (revision 0)
> @@ -0,0 +1,202 @@
> +/*
> +
> + Derby - Class org.apache.derbyTesting.functionTests.tests.store.TestNoSyncs
> +
> + Copyright 2002, 2005 The Apache Software Foundation or its licensors, as applicable.
> +
> + Licensed under the Apache License, Version 2.0 (the "License");
> + you may not use this file except in compliance with the License.
> + You may obtain a copy of the License at
> +
> + http://www.apache.org/licenses/LICENSE-2.0
> +
> + Unless required by applicable law or agreed to in writing, software
> + distributed under the License is distributed on an "AS IS" BASIS,
> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + See the License for the specific language governing permissions and
> + limitations under the License.
> +
> + */
> +
> +package org.apache.derbyTesting.functionTests.tests.store;
> +
> +import java.sql.Connection;
> +import java.sql.Statement;
> +import java.sql.PreparedStatement;
> +import java.io.*;
> +/**
> + * This program tests the system when the derby.system.testMode property is enabled
> + *
> + * When the derby.system.testMode is set, the system will not do any sync to the disk and
> + * the recovery system will not work property.
> + * It is provided for performance reasons and should ideally only be used
> + * when there is no requirement for the database to recover.
> + * <p>
> + * When set, the system will not do any syncs, the cases namely
> + * - no sync of the log file at each commit
> + * - no sync of the log file before data page is forced to disk
> + * - no sync of page allocation when file is grown
> + * - no sync of data writes during checkpoint
> + * <p>
> + * That means, when this property is set to true,
> + * - a commit no longer guarantees that the transaction's modification
> + * will survive a system crash or JVM termination
> + * - the database may not recover successfully upon restart
> + * - a near full disk at runtime may cause unexpected errors
> + *
> + * This program tests for
> + * 1. enabling the derby.system.testMode is actually not doing the syncs
> + * by timing inserts
> + * 2. check if a warning message exists in derby.log
> + * 3. read log.ctrl file and check if the flag is set or not
> + *
> + *
> + * @author <a href="mailto:ksunithaghm@gmail.com">Sunitha Kambhampati</a>
> + * @version 1.0
> + */
> +public class TestNoSyncMode
> +{
> + public static void main(String[] args)
> + {
> + Connection conn = null;
> + Statement s = null;
> + PreparedStatement ps = null;
> + try
> + {
> + // use the ij utility to read the property file and
> + // make the initial connection.
> + org.apache.derby.tools.ij.getPropertyArg(args);
> + conn = org.apache.derby.tools.ij.startJBMS();
> +
> + s = conn.createStatement();
> + s.execute("create table t1 (c1 int, c2 int)");
> + s.close();
> +
> + // Test 1
> + // this is a quick check incase someone breaks the derby.system.testMode
> + long timeTaken = doInsertsInAutoCommit(conn);
> + conn.close();
> +
> + int approxUpperBound = 3000; // approximate upper bound in millisecond
> + if ( timeTaken > approxUpperBound )
> + {
> + report("FAIL -- derby.system.testMode mode seems to be broken.");
> + report(" Time to insert rows in test exceeded the usual limit.");
> + }
> +
> + // Test 2
> + // Check if derby.log has the warning message
> + report("Is warning message about derby.system.testMode present in derby.log ="+ isMessageInDerbyLog());
> + // Test 3
> + // Check if marker is correctly written out to database
> + markerInControlFile();
> +
> +
> + }
> + catch (Throwable e) {
> + report("FAIL -- unexpected exception: "+e);
> + e.printStackTrace();
> + }
> +
> + }
> +
> +
> + /**
> + * Note doing inserts in autocommit mode is probably the worst case scenario
> + * in terms of performance as each commit will involve a flush/sync to disk
> + * but in case of the derby.system.testMode=true mode, the syncs dont happen
> + * This test case times the inserts and assumes that the inserts on any system
> + * will be less than three second for 500 inserts.
> + * Note this upper bound on time is just an approximate estimation
> + */
> + public static long doInsertsInAutoCommit(Connection conn)
> + throws Exception
> + {
> + PreparedStatement ps = conn.prepareStatement("insert into t1 values(?,?)");
> + long count = 0;
> +
> + long start = System.currentTimeMillis();
> +
> + for ( int i = 0; i < 500; i++ )
> + {
> + ps.setInt(1,i);
> + ps.setInt(2,i);
> + count += ps.executeUpdate();
> + }
> +
> + long end = System.currentTimeMillis();
> + report("num successful inserts = "+count);
> +
> + return ( end - start);
> + }
> +
> + /**
> + * When derby.system.testMode is set, a warning message is written out to derby.log
> + * indicating that the property is set and that it does not guarantee recoverability
> + * This test tests if a message is written out to derby.log or not
> + */
> + public static boolean isMessageInDerbyLog()
> + throws Exception
> + {
> + BufferedReader reader = null;
> + File derbylog = null;
> + try
> + {
> + String derbyHome = System.getProperty("derby.system.home");
> + derbylog = new File(derbyHome,"derby.log");
> + reader = new BufferedReader(new FileReader(derbylog));
> +
> + String line = null;
> + while((line = reader.readLine())!= null)
> + {
> + if(line.indexOf("derby.system.testMode") != -1)
> + return true;
> +
> + }
> + return false;
> + }
> + finally
> + {
> + if (reader != null)
> + {
> + reader.close();
> + }
> + derbylog = null;
> + }
> + }
> +
> + /**
> + * if derby.system.testMode is set, a marker is written out into log control file
> + * to recognize that the database was previously booted in this mode
> + * Test if the marker byte is set correctly or not
> + * See comments in org.apache.derby.impl.store.log.LogToFile for IS_TESTMODE_NO_SYNC_FLAG
> + */
> + public static void markerInControlFile()
> + throws Exception
> + {
> + RandomAccessFile controlFile = null;
> + try
> + {
> + int testModeNoSyncMarkerPosition = 29;
> + String derbyHome = System.getProperty("derby.system.home");
> + controlFile = new RandomAccessFile(derbyHome+"/wombat/log/log.ctrl","r");
> + controlFile.seek(testModeNoSyncMarkerPosition);
> + report("log.ctrl file has testMode NoSync marker value = "+ controlFile.readByte());
> + }
> + finally
> + {
> + if(controlFile != null)
> + controlFile.close();
> +
> + }
> + }
> +
> + public static void report(String msg)
> + {
> + System.out.println(msg);
> + }
> +
> +}
> +
> +
> +
>
> Property changes on: java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode.java
> ___________________________________________________________________
> Name: svn:eol-style
> + native
>
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant (revision 165265)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/store/copyfiles.ant (working copy)
> @@ -23,6 +23,7 @@
> TransactionTable.sql
> TransactionTable_app.properties
> TransactionTable_derby.properties
> +TestNoSyncMode_derby.properties
> access.sql
> access_app.properties
> access_derby.properties
> Index: java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties (revision 0)
> +++ java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties (revision 0)
> @@ -0,0 +1 @@
> +derby.system.testMode=true
>
> Property changes on: java/testing/org/apache/derbyTesting/functionTests/tests/store/TestNoSyncMode_derby.properties
> ___________________________________________________________________
> Name: svn:eol-style
> + native
>
> Index: java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out (revision 0)
> +++ java/testing/org/apache/derbyTesting/functionTests/master/TestNoSyncMode.out (revision 0)
> @@ -0,0 +1,3 @@
> +num successful inserts = 500
> +Is warning message about derby.system.testMode present in derby.log =true
> +log.ctrl file has testMode NoSync marker value = 1
> Index: java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall
> ===================================================================
> --- java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall (revision 165265)
> +++ java/testing/org/apache/derbyTesting/functionTests/suites/storemats.runall (working copy)
> @@ -4,3 +4,4 @@
> store/longColumn.sql
> store/madhare.sql
> store/streamingColumn.java
> +store/TestNoSyncMode.java
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Suresh Thalamati <su...@gmail.com>.
sure. I will review it.
-suresh
Mike Matrigali wrote:
> suresh, you have done a lot of work in this area could you review
> the patch and post your comments?
>
>
>
> Sunitha Kambhampati wrote:
>
>> A little background: Sometime earlier on the list, Dan posted a fix
>> to make derby go faster with relaxed durability with some flags. The
>> post is at
>> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>
>> This mode is very useful for unit testing or at development time when
>> recoverability is not required.
>> Basically in this mode, syncs are disabled for logs, data writes at
>> checkpoint, page allocation when file is grown; - what this means is
>> that data is not flushed all the way to the disk and in most cases
>> i/o cost is not involved. Note, code already exists in Derby to do
>> this.
>> So for Derby 218, This patch addresses the following requirements:
>> 1) Have a single property to enable this relaxed durability mode, so
>> it is easy for users to enable it.
>> 2) Print message to derby.log that this mode is enabled
>> 3) A way to report boot errors that may be because of this option
>> being enabled. What this maps to is - have a marker to recognize that
>> database was booted in this mode, and then on subsequent boot; if
>> errors happen during recovery - report a message that it could have
>> happened because of this mode being set.
>
> > ... deleted ...
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Mike Matrigali <mi...@sbcglobal.net>.
suresh, you have done a lot of work in this area could you review
the patch and post your comments?
Sunitha Kambhampati wrote:
> A little background: Sometime earlier on the list, Dan posted a fix to
> make derby go faster with relaxed durability with some flags. The post
> is at
> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>
> This mode is very useful for unit testing or at development time when
> recoverability is not required.
> Basically in this mode, syncs are disabled for logs, data writes at
> checkpoint, page allocation when file is grown; - what this means is
> that data is not flushed all the way to the disk and in most cases i/o
> cost is not involved. Note, code already exists in Derby to do this.
> So for Derby 218, This patch addresses the following requirements: 1)
> Have a single property to enable this relaxed durability mode, so it is
> easy for users to enable it.
> 2) Print message to derby.log that this mode is enabled
> 3) A way to report boot errors that may be because of this option being
> enabled. What this maps to is - have a marker to recognize that database
> was booted in this mode, and then on subsequent boot; if errors happen
> during recovery - report a message that it could have happened because
> of this mode being set.
> ... deleted ...
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Sunitha Kambhampati <ks...@gmail.com>.
Sunitha Kambhampati wrote:
> David Van Couvering wrote:
>
>> Great! I have a question: if I wanted to use this to speed up
>> testing, how do I do it within the context of the test harness?
>>
> To enable this mode for derbyall suite.
> put the following property in
> java\testing\org\apache\derbyTesting\functionTests\suites\derbyall.properties
>
> derby.system.durability=test
>
> build it ( ant testing).
>
> Then I believe, when you run derbyall, this property will be picked up
> by all the tests run as part of derbyall.
>
Also, if you want to doublecheck if this property is picked up correctly
or not, in the window where you are running the derbyall suite, you
should see the derby.system.durability=test property passed as part of
testSpecialProps for the tests..
Execute command: java -DjavaCmd=java
-Doutputdir=C:\workghm\svnclient\trunk\test
ing\derbyall\derbylang
-Dtopsuitedir=C:\workghm\svnclient\trunk\testing\derbyall
-Dtopreportdir=C:\workghm\svnclient\trunk\testing\derbyall
-Drundir=C:\workghm\
svnclient\trunk\testing
-DtestSpecialProps=derby.debug.true=enableBtreeConsisten
cyCheck^*derby.system.durability=test*^derby.stream.error.logSeverityLevel=0
-Dsui
tename=derbyall:derbylang -Dtopsuitename=derbyall
org.apache.derbyTesting.functi
onTests.harness.RunTest lang/errorCode.sql
Also, you should also see the following warning in derby.log :
"
WARNING: The database is booted with derby.system.durability=test. In
this mode, it is possible that database may not be able to recover,
committed transactions may be lost, database may be in an inconsistent
state. Please use this mode only when these consequences are acceptable "
_____________
Sunitha.
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Mike Matrigali <mi...@sbcglobal.net>.
let us know if this works. There are some recovery/crash tests in the
full suite. My guess is that they will work since the I/O is sent to
the OS, just not sync's -- but they are not guaranteed to work under
this mode.
Sunitha Kambhampati wrote:
> David Van Couvering wrote:
>
>> Great! I have a question: if I wanted to use this to speed up
>> testing, how do I do it within the context of the test harness?
>>
> To enable this mode for derbyall suite.
> put the following property in
> java\testing\org\apache\derbyTesting\functionTests\suites\derbyall.properties
>
> derby.system.durability=test
>
> build it ( ant testing).
>
> Then I believe, when you run derbyall, this property will be picked up
> by all the tests run as part of derbyall.
>
> Sunitha.
>
>>
>> Mike Matrigali wrote:
>>
>>> I committed this change with svn 169538.
>>>
>>> Sunitha Kambhampati wrote:
>>>
>>>> Mike Matrigali wrote:
>>>>
>>>>> Could you resolve the conflict in LogToFile.java in the current trunk
>>>>> revision and resubmit the patch?
>>>>>
>>>> I resolved the conflict and regenerated the
>>>> patch(DurabilityTest_0510.txt). Let me know if you have any problems
>>>> applying this patch.
>>>>
>>>> Thanks,
>>>> Sunitha.
>>>>
>>>>> Sunitha Kambhampati wrote:
>>>>>
>>>>>> Thanks Suresh for your comments. I have attached a new patch that
>>>>>> takes care of them and as well as the property name change as
>>>>>> discussed on the list.
>>>>>>
>>>>>> So now,
>>>>>> 1)To enable this no syncs mode, the property setting is
>>>>>> derby.system.durability=test If it is set to any other value
>>>>>> other than test, then this property setting is ignored and the
>>>>>> system will default to the usual mode where all syncs happen
>>>>>> correctly.
>>>>>> 2) If database is booted in this mode then the flag to indicate
>>>>>> this mode is being used is set in log.ctrl file and it will not
>>>>>> change after that.Thus there wont be any switching between this
>>>>>> mode ( no syncs) to default ( all syncs) mode because we cannot
>>>>>> guarantee that the database will be in a consistent state once its
>>>>>> booted in this no sync mode..
>>>>>> 3) This flag is now written out as part of the log control flags
>>>>>> in log.ctrl file instead of using a spare byte.
>>>>>> _______________________
>>>>>
>>>>>
>>>
>>> deleted rest ...
>>>
>>
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by David Van Couvering <Da...@Sun.COM>.
Thanks. Are there any tests that *shouldn't* be run in this mode, e.g.
recovery tests?
David
Daniel John Debrunner wrote:
> Sunitha Kambhampati wrote:
>
>
>>David Van Couvering wrote:
>>
>>
>>>Great! I have a question: if I wanted to use this to speed up
>>>testing, how do I do it within the context of the test harness?
>>>
>>
>>To enable this mode for derbyall suite.
>>put the following property in
>>java\testing\org\apache\derbyTesting\functionTests\suites\derbyall.properties
>>
>>derby.system.durability=test
>
>
> I think this will work as an alternative, and means you don't have to
> modify any files
>
> java -Dderby.system.durability=test
> -Djvmflags="-Dderby.system.durability=test"
> org.apache.derbyTesting.functionTests.harness.RunSuite derbyall
>
>
> The -Dderby.system.durability to the java command ensures the property
> will be set for any tests run in-process, e.g. nist
>
> The setting in the jvmflags ensures it is passed on to the JVM's spawned
> to run most tests.
>
> Dan.
>
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by David Van Couvering <Da...@Sun.COM>.
Thanks, Dan. Yes, I would love to move to JUnit too, that has my vote.
David
Daniel John Debrunner wrote:
> David Van Couvering wrote:
>
>
>>FYI, your suggestion worked great on XP, but on Linux I got a strange
>>error in tests that spawn another JVM:
>>
>>Exception in thread "main" java.lang.NoClassDefFoundError:
>>"-Dderby/system/durability=test"
>
>
> Getting the quoting to work when passing setting jvmflags seems a major
> pain. Take a look at the j9 thread to see how I managed to get jvmflags
> to work when it included multiple -D options, may help, but it was on XP
> as well. You can use -Dverbose=true on the outer jvm to see the command
> line for the spawned jvm, that might give clues.
>
> Now if we used JUnit this wouldn't be an issue ...
> (I'll just keep repeating this ... :-)
>
> Dan.
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Daniel John Debrunner <dj...@debrunners.com>.
David Van Couvering wrote:
> FYI, your suggestion worked great on XP, but on Linux I got a strange
> error in tests that spawn another JVM:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> "-Dderby/system/durability=test"
Getting the quoting to work when passing setting jvmflags seems a major
pain. Take a look at the j9 thread to see how I managed to get jvmflags
to work when it included multiple -D options, may help, but it was on XP
as well. You can use -Dverbose=true on the outer jvm to see the command
line for the spawned jvm, that might give clues.
Now if we used JUnit this wouldn't be an issue ...
(I'll just keep repeating this ... :-)
Dan.
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by David Van Couvering <Da...@Sun.COM>.
FYI, your suggestion worked great on XP, but on Linux I got a strange
error in tests that spawn another JVM:
Exception in thread "main" java.lang.NoClassDefFoundError:
"-Dderby/system/durability=test"
I am will try to track this down, but meanwhile I'm modifying
derbyall.properties...
David
Daniel John Debrunner wrote:
> Sunitha Kambhampati wrote:
>
>
>>David Van Couvering wrote:
>>
>>
>>>Great! I have a question: if I wanted to use this to speed up
>>>testing, how do I do it within the context of the test harness?
>>>
>>
>>To enable this mode for derbyall suite.
>>put the following property in
>>java\testing\org\apache\derbyTesting\functionTests\suites\derbyall.properties
>>
>>derby.system.durability=test
>
>
> I think this will work as an alternative, and means you don't have to
> modify any files
>
> java -Dderby.system.durability=test
> -Djvmflags="-Dderby.system.durability=test"
> org.apache.derbyTesting.functionTests.harness.RunSuite derbyall
>
>
> The -Dderby.system.durability to the java command ensures the property
> will be set for any tests run in-process, e.g. nist
>
> The setting in the jvmflags ensures it is passed on to the JVM's spawned
> to run most tests.
>
> Dan.
>
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by David Van Couvering <Da...@Sun.COM>.
FYI, your suggestion worked great on XP, but on Linux I got a strange
error in tests that spawn another JVM:
Exception in thread "main" java.lang.NoClassDefFoundError:
"-Dderby/system/durability=test"
I am working on tracking this down, but meanwhile I'm modifying
derbyall.properties...
David
Daniel John Debrunner wrote:
> Sunitha Kambhampati wrote:
>
>
>>David Van Couvering wrote:
>>
>>
>>>Great! I have a question: if I wanted to use this to speed up
>>>testing, how do I do it within the context of the test harness?
>>>
>>
>>To enable this mode for derbyall suite.
>>put the following property in
>>java\testing\org\apache\derbyTesting\functionTests\suites\derbyall.properties
>>
>>derby.system.durability=test
>
>
> I think this will work as an alternative, and means you don't have to
> modify any files
>
> java -Dderby.system.durability=test
> -Djvmflags="-Dderby.system.durability=test"
> org.apache.derbyTesting.functionTests.harness.RunSuite derbyall
>
>
> The -Dderby.system.durability to the java command ensures the property
> will be set for any tests run in-process, e.g. nist
>
> The setting in the jvmflags ensures it is passed on to the JVM's spawned
> to run most tests.
>
> Dan.
>
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Daniel John Debrunner <dj...@debrunners.com>.
Sunitha Kambhampati wrote:
> David Van Couvering wrote:
>
>> Great! I have a question: if I wanted to use this to speed up
>> testing, how do I do it within the context of the test harness?
>>
> To enable this mode for derbyall suite.
> put the following property in
> java\testing\org\apache\derbyTesting\functionTests\suites\derbyall.properties
>
> derby.system.durability=test
I think this will work as an alternative, and means you don't have to
modify any files
java -Dderby.system.durability=test
-Djvmflags="-Dderby.system.durability=test"
org.apache.derbyTesting.functionTests.harness.RunSuite derbyall
The -Dderby.system.durability to the java command ensures the property
will be set for any tests run in-process, e.g. nist
The setting in the jvmflags ensures it is passed on to the JVM's spawned
to run most tests.
Dan.
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Sunitha Kambhampati <ks...@gmail.com>.
David Van Couvering wrote:
> Great! I have a question: if I wanted to use this to speed up
> testing, how do I do it within the context of the test harness?
>
To enable this mode for derbyall suite.
put the following property in
java\testing\org\apache\derbyTesting\functionTests\suites\derbyall.properties
derby.system.durability=test
build it ( ant testing).
Then I believe, when you run derbyall, this property will be picked up
by all the tests run as part of derbyall.
Sunitha.
>
> Mike Matrigali wrote:
>
>> I committed this change with svn 169538.
>>
>> Sunitha Kambhampati wrote:
>>
>>> Mike Matrigali wrote:
>>>
>>>> Could you resolve the conflict in LogToFile.java in the current trunk
>>>> revision and resubmit the patch?
>>>>
>>> I resolved the conflict and regenerated the
>>> patch(DurabilityTest_0510.txt). Let me know if you have any problems
>>> applying this patch.
>>>
>>> Thanks,
>>> Sunitha.
>>>
>>>> Sunitha Kambhampati wrote:
>>>>
>>>>> Thanks Suresh for your comments. I have attached a new patch that
>>>>> takes care of them and as well as the property name change as
>>>>> discussed on the list.
>>>>>
>>>>> So now,
>>>>> 1)To enable this no syncs mode, the property setting is
>>>>> derby.system.durability=test If it is set to any other value
>>>>> other than test, then this property setting is ignored and the
>>>>> system will default to the usual mode where all syncs happen
>>>>> correctly.
>>>>> 2) If database is booted in this mode then the flag to indicate
>>>>> this mode is being used is set in log.ctrl file and it will not
>>>>> change after that.Thus there wont be any switching between this
>>>>> mode ( no syncs) to default ( all syncs) mode because we cannot
>>>>> guarantee that the database will be in a consistent state once its
>>>>> booted in this no sync mode..
>>>>> 3) This flag is now written out as part of the log control flags
>>>>> in log.ctrl file instead of using a spare byte.
>>>>> _______________________
>>>>
>>
>> deleted rest ...
>>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by David Van Couvering <Da...@Sun.COM>.
Great! I have a question: if I wanted to use this to speed up testing,
how do I do it within the context of the test harness?
Thanks,
David
Mike Matrigali wrote:
> I committed this change with svn 169538.
>
> Sunitha Kambhampati wrote:
>
>> Mike Matrigali wrote:
>>
>>> Could you resolve the conflict in LogToFile.java in the current trunk
>>> revision and resubmit the patch?
>>>
>> I resolved the conflict and regenerated the
>> patch(DurabilityTest_0510.txt). Let me know if you have any problems
>> applying this patch.
>>
>> Thanks,
>> Sunitha.
>>
>>> Sunitha Kambhampati wrote:
>>>
>>>> Thanks Suresh for your comments. I have attached a new patch that
>>>> takes care of them and as well as the property name change as
>>>> discussed on the list.
>>>>
>>>> So now,
>>>> 1)To enable this no syncs mode, the property setting is
>>>> derby.system.durability=test If it is set to any other value other
>>>> than test, then this property setting is ignored and the system will
>>>> default to the usual mode where all syncs happen correctly.
>>>> 2) If database is booted in this mode then the flag to indicate
>>>> this mode is being used is set in log.ctrl file and it will not
>>>> change after that.Thus there wont be any switching between this mode
>>>> ( no syncs) to default ( all syncs) mode because we cannot guarantee
>>>> that the database will be in a consistent state once its booted in
>>>> this no sync mode..
>>>> 3) This flag is now written out as part of the log control flags in
>>>> log.ctrl file instead of using a spare byte.
>>>> _______________________
>
> deleted rest ...
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Mike Matrigali <mi...@sbcglobal.net>.
I committed this change with svn 169538.
Sunitha Kambhampati wrote:
> Mike Matrigali wrote:
>
>> Could you resolve the conflict in LogToFile.java in the current trunk
>> revision and resubmit the patch?
>>
> I resolved the conflict and regenerated the
> patch(DurabilityTest_0510.txt). Let me know if you have any problems
> applying this patch.
>
> Thanks,
> Sunitha.
>
>> Sunitha Kambhampati wrote:
>>
>>> Thanks Suresh for your comments. I have attached a new patch that
>>> takes care of them and as well as the property name change as
>>> discussed on the list.
>>>
>>> So now,
>>> 1)To enable this no syncs mode, the property setting is
>>> derby.system.durability=test If it is set to any other value other
>>> than test, then this property setting is ignored and the system will
>>> default to the usual mode where all syncs happen correctly.
>>> 2) If database is booted in this mode then the flag to indicate
>>> this mode is being used is set in log.ctrl file and it will not
>>> change after that.Thus there wont be any switching between this mode
>>> ( no syncs) to default ( all syncs) mode because we cannot guarantee
>>> that the database will be in a consistent state once its booted in
>>> this no sync mode..
>>> 3) This flag is now written out as part of the log control flags in
>>> log.ctrl file instead of using a spare byte.
>>> _______________________
deleted rest ...
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Sunitha Kambhampati <ks...@gmail.com>.
Mike Matrigali wrote:
> Could you resolve the conflict in LogToFile.java in the current trunk
> revision and resubmit the patch?
>
I resolved the conflict and regenerated the
patch(DurabilityTest_0510.txt). Let me know if you have any problems
applying this patch.
Thanks,
Sunitha.
> Sunitha Kambhampati wrote:
>
>> Thanks Suresh for your comments. I have attached a new patch that
>> takes care of them and as well as the property name change as
>> discussed on the list.
>>
>> So now,
>> 1)To enable this no syncs mode, the property setting is
>> derby.system.durability=test If it is set to any other value other
>> than test, then this property setting is ignored and the system will
>> default to the usual mode where all syncs happen correctly.
>> 2) If database is booted in this mode then the flag to indicate
>> this mode is being used is set in log.ctrl file and it will not
>> change after that.Thus there wont be any switching between this mode
>> ( no syncs) to default ( all syncs) mode because we cannot guarantee
>> that the database will be in a consistent state once its booted in
>> this no sync mode..
>> 3) This flag is now written out as part of the log control flags in
>> log.ctrl file instead of using a spare byte.
>> _______________________
>> svn stat:
>> M java\engine\org\apache\derby\impl\store\raw\log\LogToFile.java
>> M
>> java\engine\org\apache\derby\impl\store\raw\data\BaseDataFileFactory.java
>>
>> M
>> java\engine\org\apache\derby\impl\store\raw\data\RAFContainer.java
>> M java\engine\org\apache\derby\iapi\reference\MessageId.java
>> M java\engine\org\apache\derby\iapi\reference\Property.java
>> M java\engine\org\apache\derby\loc\messages_en.properties
>> A
>> java\testing\org\apache\derbyTesting\functionTests\tests\store\TestDurabilityProperty.java
>>
>> A
>> java\testing\org\apache\derbyTesting\functionTests\master\TestDurabilityProperty.out
>>
>> M
>> java\testing\org\apache\derbyTesting\functionTests\suites\storemats.runall
>>
>>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Mike Matrigali <mi...@sbcglobal.net>.
Could you resolve the conflict in LogToFile.java in the current trunk
revision and resubmit the patch?
Sunitha Kambhampati wrote:
> Thanks Suresh for your comments. I have attached a new patch that takes
> care of them and as well as the property name change as discussed on the
> list.
>
> So now,
> 1)To enable this no syncs mode, the property setting is
> derby.system.durability=test If it is set to any other value other than
> test, then this property setting is ignored and the system will default
> to the usual mode where all syncs happen correctly.
> 2) If database is booted in this mode then the flag to indicate this
> mode is being used is set in log.ctrl file and it will not change after
> that.Thus there wont be any switching between this mode ( no syncs) to
> default ( all syncs) mode because we cannot guarantee that the database
> will be in a consistent state once its booted in this no sync mode..
> 3) This flag is now written out as part of the log control flags in
> log.ctrl file instead of using a spare byte.
> _______________________
> svn stat:
> M java\engine\org\apache\derby\impl\store\raw\log\LogToFile.java
> M
> java\engine\org\apache\derby\impl\store\raw\data\BaseDataFileFactory.java
> M java\engine\org\apache\derby\impl\store\raw\data\RAFContainer.java
> M java\engine\org\apache\derby\iapi\reference\MessageId.java
> M java\engine\org\apache\derby\iapi\reference\Property.java
> M java\engine\org\apache\derby\loc\messages_en.properties
> A
> java\testing\org\apache\derbyTesting\functionTests\tests\store\TestDurabilityProperty.java
>
> A
> java\testing\org\apache\derbyTesting\functionTests\master\TestDurabilityProperty.out
>
> M
> java\testing\org\apache\derbyTesting\functionTests\suites\storemats.runall
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Sunitha Kambhampati <ks...@gmail.com>.
Thanks Suresh for your comments. I have attached a new patch that takes
care of them and as well as the property name change as discussed on the
list.
So now,
1)To enable this no syncs mode, the property setting is
derby.system.durability=test
If it is set to any other value other than test, then this property
setting is ignored and the system will default to the usual mode where
all syncs happen correctly.
2) If database is booted in this mode then the flag to indicate this
mode is being used is set in log.ctrl file and it will not change after
that.Thus there wont be any switching between this mode ( no syncs) to
default ( all syncs) mode because we cannot guarantee that the database
will be in a consistent state once its booted in this no sync mode..
3) This flag is now written out as part of the log control flags in
log.ctrl file instead of using a spare byte.
_______________________
svn stat:
M java\engine\org\apache\derby\impl\store\raw\log\LogToFile.java
M
java\engine\org\apache\derby\impl\store\raw\data\BaseDataFileFactory.java
M java\engine\org\apache\derby\impl\store\raw\data\RAFContainer.java
M java\engine\org\apache\derby\iapi\reference\MessageId.java
M java\engine\org\apache\derby\iapi\reference\Property.java
M java\engine\org\apache\derby\loc\messages_en.properties
A
java\testing\org\apache\derbyTesting\functionTests\tests\store\TestDurabilityProperty.java
A
java\testing\org\apache\derbyTesting\functionTests\master\TestDurabilityProperty.out
M
java\testing\org\apache\derbyTesting\functionTests\suites\storemats.runall
I use eclipse IDE and have it set to put 4 spaces for tab ( as per
discussion on formatting on the list). I did verify by opening the files
in viw ( with tab set to 4) and the formatting looks ok. But even when
I sent the patch last time, in eclipse the formatting looked ok, so not
totally sure what may be happening. But if someone finds any issue with
formatting please let me know.
Can someone review it and if it looks ok, can a committer commit it.
Thanks,
Sunitha.
Mike Matrigali wrote:
> <>I think that once the db is run in this mode it should be marked, and
> not worry about ever unmarking it. At first I just thought this was
> necessary to explain lost transactions, but I agree with the case below
> - successful recovery/booting does not guarantee consistent database.
> The case that you describe below can easily result in an index entry
> pointing to a non-existent base table row - with all the subsequent
> runtime errors later on.
>
> So I would lean toward changing to single flag, set once and never
> untoggled. .......
> <>Suresh Thalamati wrote:
>>Hi Sunitha,
>>
>>Good comments. I am surprised to find that this patch doing more than
>>what I imagined it will do, your changes
>>seems to allow switching between durable test mode(No syncs) and the
>>default durability level (all sync). I don't get why
>>these mode switch functionality is required, if this mode is just meant
>>to run the tests faster in non-durable mode! . Not sure what
>>kind of new problem scenarios this mode switching will introduce.
>>
>>But for some reason if some one wants, I am not sure your fix will
>>actually make a non-durable database
>>to durable/consistent one correctly. What I learn from your changes
>>is that data is not synced to disk on checkpoints,
>>if you don't do that you can not assume database is is in consistent
>>state if recovery went through fine. Let's say:
>>
>>1) user started the database with derby.system.testMode=true
>>2) did some insert/update/deletes ...
>>3) crashed immediately after the checpoint record got on to disk...
>>4) Now user switches derby.system.testMode=false and boot the database.
>>
>>Recovery will work fine because there is no log to replay. So you
>>unmark the
>>Test mode flag in the control file and declare that this database is in
>>durable/consistent mode.
>>But that is not the case because only some of the data pages might
>>have reached to the
>>disk before the crash, Which will actually leave the database
>>inconsistent state.
>>(This is different from losing some transactions).
>>
>>Some general comments on the code:
>>1) Why don't we just introduce a new flag private static final byte
>>TESTMODE_NO_SYNC_TRUE = 0x2 and
>> write as part of the "flags" byte which is currently used to
>>indicate the IS_BETA_FLAG instead of using
>> another spare byte.
>>2) in few places indentation is not matching the rest of the code(
>>that's how my emacs shows it):
>> a)
>> // if system is running with derby.system.testMode enabled
>> // log records and log file are not synced, so
>> // set flag to disable log syncs
>> b)
>> {
>> // print message stating that the database was
>> // previously running with derby.system.testMode=true
>> // mode
>> c) if( wasDBInTestModeNoSync && !logNotSynced )
>> {
>> // write to log control file and the mirror file that the testmode
>> // is not used now
>> d) if(wasDBInTestModeNoSync)
>> {
>> // print message stating that the database was
>> // previously running with derby.system.testMode=true
>> ......etc.
>>
>>3) I think the logical place for the method private boolean
>>updateTestModeFlagInCtrlFile(byte value)
>> is next to writeControlFile(...) .
>>
>>4) protected logErrMsgForTestModeNoSync() may be marked as a private.
>>
>>
>>Thanks
>>-suresht
>>
>>
>>Sunitha Kambhampati wrote:
>>
>>
>>
>>>A little background: Sometime earlier on the list, Dan posted a fix to
>>>make derby go faster with relaxed durability with some flags. The
>>>post is at
>>>http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>>
>>>This mode is very useful for unit testing or at development time when
>>>recoverability is not required.
>>>Basically in this mode, syncs are disabled for logs, data writes at
>>>checkpoint, page allocation when file is grown; - what this means is
>>>that data is not flushed all the way to the disk and in most cases i/o
>>>cost is not involved. Note, code already exists in Derby to do this.
>>>So for Derby 218, This patch addresses the following requirements:
>>>1) Have a single property to enable this relaxed durability mode, so
>>>it is easy for users to enable it.
>>>2) Print message to derby.log that this mode is enabled
>>>3) A way to report boot errors that may be because of this option
>>>being enabled. What this maps to is - have a marker to recognize that
>>>database was booted in this mode, and then on subsequent boot; if
>>>errors happen during recovery - report a message that it could have
>>>happened because of this mode being set.
>>>
>>>Ch
>>>
>>>
>>............
>>
>>
>>
>>
>
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Mike Matrigali <mi...@sbcglobal.net>.
I think that once the db is run in this mode it should be marked, and
not worry about ever unmarking it. At first I just thought this was
necessary to explain lost transactions, but I agree with the case below
- successful recovery/booting does not guarantee consistent database.
The case that you describe below can easily result in an index entry
pointing to a non-existent base table row - with all the subsequent
runtime errors later on.
So I would lean toward changing to single flag, set once and never
untoggled. Change the property name to something like
derby.system.durability=test. Fix the comments below. resubmit
patch.
If anyone else is planning on testing/review the patch let the list
know.
/mikem
Suresh Thalamati wrote:
> Hi Sunitha,
>
> Good comments. I am surprised to find that this patch doing more than
> what I imagined it will do, your changes
> seems to allow switching between durable test mode(No syncs) and the
> default durability level (all sync). I don't get why
> these mode switch functionality is required, if this mode is just meant
> to run the tests faster in non-durable mode! . Not sure what
> kind of new problem scenarios this mode switching will introduce.
>
> But for some reason if some one wants, I am not sure your fix will
> actually make a non-durable database
> to durable/consistent one correctly. What I learn from your changes
> is that data is not synced to disk on checkpoints,
> if you don't do that you can not assume database is is in consistent
> state if recovery went through fine. Let's say:
>
> 1) user started the database with derby.system.testMode=true
> 2) did some insert/update/deletes ...
> 3) crashed immediately after the checpoint record got on to disk...
> 4) Now user switches derby.system.testMode=false and boot the database.
>
> Recovery will work fine because there is no log to replay. So you
> unmark the
> Test mode flag in the control file and declare that this database is in
> durable/consistent mode.
> But that is not the case because only some of the data pages might
> have reached to the
> disk before the crash, Which will actually leave the database
> inconsistent state.
> (This is different from losing some transactions).
>
> Some general comments on the code:
> 1) Why don't we just introduce a new flag private static final byte
> TESTMODE_NO_SYNC_TRUE = 0x2 and
> write as part of the "flags" byte which is currently used to
> indicate the IS_BETA_FLAG instead of using
> another spare byte.
> 2) in few places indentation is not matching the rest of the code(
> that's how my emacs shows it):
> a)
> // if system is running with derby.system.testMode enabled
> // log records and log file are not synced, so
> // set flag to disable log syncs
> b)
> {
> // print message stating that the database was
> // previously running with derby.system.testMode=true
> // mode
> c) if( wasDBInTestModeNoSync && !logNotSynced )
> {
> // write to log control file and the mirror file that the testmode
> // is not used now
> d) if(wasDBInTestModeNoSync)
> {
> // print message stating that the database was
> // previously running with derby.system.testMode=true
> ......etc.
>
> 3) I think the logical place for the method private boolean
> updateTestModeFlagInCtrlFile(byte value)
> is next to writeControlFile(...) .
>
> 4) protected logErrMsgForTestModeNoSync() may be marked as a private.
>
>
> Thanks
> -suresht
>
>
> Sunitha Kambhampati wrote:
>
>> A little background: Sometime earlier on the list, Dan posted a fix to
>> make derby go faster with relaxed durability with some flags. The
>> post is at
>> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>>
>> This mode is very useful for unit testing or at development time when
>> recoverability is not required.
>> Basically in this mode, syncs are disabled for logs, data writes at
>> checkpoint, page allocation when file is grown; - what this means is
>> that data is not flushed all the way to the disk and in most cases i/o
>> cost is not involved. Note, code already exists in Derby to do this.
>> So for Derby 218, This patch addresses the following requirements:
>> 1) Have a single property to enable this relaxed durability mode, so
>> it is easy for users to enable it.
>> 2) Print message to derby.log that this mode is enabled
>> 3) A way to report boot errors that may be because of this option
>> being enabled. What this maps to is - have a marker to recognize that
>> database was booted in this mode, and then on subsequent boot; if
>> errors happen during recovery - report a message that it could have
>> happened because of this mode being set.
>>
>> Ch
>
>
> ............
>
>
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Suresh Thalamati <su...@gmail.com>.
Hi Sunitha,
Good comments. I am surprised to find that this patch doing more than
what I imagined it will do, your changes
seems to allow switching between durable test mode(No syncs) and the
default durability level (all sync). I don't get why
these mode switch functionality is required, if this mode is just meant
to run the tests faster in non-durable mode! . Not sure what
kind of new problem scenarios this mode switching will introduce.
But for some reason if some one wants, I am not sure your fix will
actually make a non-durable database
to durable/consistent one correctly. What I learn from your changes
is that data is not synced to disk on checkpoints,
if you don't do that you can not assume database is is in consistent
state if recovery went through fine. Let's say:
1) user started the database with derby.system.testMode=true
2) did some insert/update/deletes ...
3) crashed immediately after the checpoint record got on to disk...
4) Now user switches derby.system.testMode=false and boot the database.
Recovery will work fine because there is no log to replay. So you
unmark the
Test mode flag in the control file and declare that this database is in
durable/consistent mode.
But that is not the case because only some of the data pages might
have reached to the
disk before the crash, Which will actually leave the database
inconsistent state.
(This is different from losing some transactions).
Some general comments on the code:
1) Why don't we just introduce a new flag private static final byte
TESTMODE_NO_SYNC_TRUE = 0x2 and
write as part of the "flags" byte which is currently used to
indicate the IS_BETA_FLAG instead of using
another spare byte.
2) in few places indentation is not matching the rest of the code(
that's how my emacs shows it):
a)
// if system is running with derby.system.testMode enabled
// log records and log file are not synced, so
// set flag to disable log syncs
b)
{
// print message stating that the database was
// previously running with derby.system.testMode=true
// mode
c) if( wasDBInTestModeNoSync && !logNotSynced )
{
// write to log control file and the mirror file that the testmode
// is not used now
d)
if(wasDBInTestModeNoSync)
{
// print message stating that the database was
// previously running with derby.system.testMode=true
......etc.
3) I think the logical place for the method private boolean
updateTestModeFlagInCtrlFile(byte value)
is next to writeControlFile(...) .
4) protected logErrMsgForTestModeNoSync() may be marked as a private.
Thanks
-suresht
Sunitha Kambhampati wrote:
> A little background: Sometime earlier on the list, Dan posted a fix to
> make derby go faster with relaxed durability with some flags. The
> post is at
> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>
> This mode is very useful for unit testing or at development time when
> recoverability is not required.
> Basically in this mode, syncs are disabled for logs, data writes at
> checkpoint, page allocation when file is grown; - what this means is
> that data is not flushed all the way to the disk and in most cases i/o
> cost is not involved. Note, code already exists in Derby to do this.
> So for Derby 218, This patch addresses the following requirements:
> 1) Have a single property to enable this relaxed durability mode, so
> it is easy for users to enable it.
> 2) Print message to derby.log that this mode is enabled
> 3) A way to report boot errors that may be because of this option
> being enabled. What this maps to is - have a marker to recognize that
> database was booted in this mode, and then on subsequent boot; if
> errors happen during recovery - report a message that it could have
> happened because of this mode being set.
>
> Ch
............
Re: [PATCH] Derby 218 - Add relaxed durability option
Posted by Mike Matrigali <mi...@sbcglobal.net>.
I am looking at committing this patch.
Sunitha Kambhampati wrote:
> A little background: Sometime earlier on the list, Dan posted a fix to
> make derby go faster with relaxed durability with some flags. The post
> is at
> http://article.gmane.org/gmane.comp.apache.db.derby.user/681/match=relaxed+durability
>
> This mode is very useful for unit testing or at development time when
> recoverability is not required.
> Basically in this mode, syncs are disabled for logs, data writes at
> checkpoint, page allocation when file is grown; - what this means is
> that data is not flushed all the way to the disk and in most cases i/o
> cost is not involved. Note, code already exists in Derby to do this.
> So for Derby 218, This patch addresses the following requirements: 1)
> Have a single property to enable this relaxed durability mode, so it is
> easy for users to enable it.
> 2) Print message to derby.log that this mode is enabled
> 3) A way to report boot errors that may be because of this option being
> enabled. What this maps to is - have a marker to recognize that database
> was booted in this mode, and then on subsequent boot; if errors happen
> during recovery - report a message that it could have happened because
> of this mode being set.
> ... rest deleted