2004-06-24 21:10:31 +00:00
|
|
|
/*--- This software is copyrighted by the Regents of the University of
|
|
|
|
California, and other parties. The following terms apply to all files
|
|
|
|
associated with the software unless explicitly disclaimed in
|
|
|
|
individual files.
|
|
|
|
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
and license this software and its documentation for any purpose,
|
|
|
|
provided that existing copyright notices are retained in all copies
|
|
|
|
and that this notice is included verbatim in any distributions. No
|
|
|
|
written agreement, license, or royalty fee is required for any of the
|
|
|
|
authorized uses. Modifications to this software may be copyrighted by
|
|
|
|
their authors and need not follow the licensing terms described here,
|
|
|
|
provided that the new terms are clearly indicated on the first page of
|
|
|
|
each file where they apply.
|
|
|
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
|
|
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
|
|
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
|
|
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
|
|
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
|
|
U.S. government, the Government shall have only "Restricted Rights" in
|
|
|
|
the software and related documentation as defined in the Federal
|
|
|
|
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
|
|
acquiring the software on behalf of the Department of Defense, the
|
|
|
|
software shall be classified as "Commercial Computer Software" and the
|
|
|
|
Government shall have only "Restricted Rights" as defined in Clause
|
|
|
|
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
|
|
authors grant the U.S. Government and others acting in its behalf
|
|
|
|
permission to use and distribute the software in accordance with the
|
|
|
|
terms specified in this license.
|
|
|
|
---*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <check.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <lladd/transactional.h>
|
2004-10-02 07:29:34 +00:00
|
|
|
#include "../../src/lladd/logger/logWriter.h"
|
2006-04-07 03:40:40 +00:00
|
|
|
#include <lladd/logger/logger2.h>
|
2004-06-24 21:10:31 +00:00
|
|
|
#include <lladd/bufferManager.h>
|
2006-05-25 00:02:46 +00:00
|
|
|
#include <lladd/truncation.h>
|
2004-06-24 21:10:31 +00:00
|
|
|
#include "../check_includes.h"
|
2004-07-23 20:21:44 +00:00
|
|
|
#include "../../src/lladd/page.h"
|
2004-08-17 01:46:17 +00:00
|
|
|
#include "../../src/lladd/page/slotted.h"
|
2004-06-24 21:10:31 +00:00
|
|
|
#define LOG_NAME "check_operations.log"
|
2004-07-14 20:49:18 +00:00
|
|
|
|
2004-10-06 06:08:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-07-14 20:49:18 +00:00
|
|
|
|
2004-10-02 07:29:34 +00:00
|
|
|
void simulateBufferManagerCrash();
|
|
|
|
extern int numActiveXactions;
|
2004-06-24 21:10:31 +00:00
|
|
|
/**
|
2004-10-02 07:29:34 +00:00
|
|
|
@test
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
Assuming that the Tset() operation is implemented correctly, checks
|
|
|
|
that doUpdate, redoUpdate and undoUpdate are working correctly, for
|
|
|
|
operations that use physical logging.
|
|
|
|
*/
|
|
|
|
START_TEST(operation_physical_do_undo) {
|
|
|
|
int xid = 1;
|
|
|
|
recordid rid;
|
2004-06-28 21:10:10 +00:00
|
|
|
lsn_t lsn = 2;
|
2004-06-24 21:10:31 +00:00
|
|
|
int buf;
|
|
|
|
int arg;
|
|
|
|
LogEntry * setToTwo;
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
Tinit();
|
2005-02-10 03:51:09 +00:00
|
|
|
xid = -1;
|
2006-06-15 05:31:20 +00:00
|
|
|
Page * p = loadPage(xid, TpageAlloc(xid));
|
|
|
|
slottedPageInitialize(p);
|
2006-06-16 00:05:44 +00:00
|
|
|
// rid = slottedPreRalloc(xid, sizeof(int), &p);
|
|
|
|
rid = slottedRawRalloc(p, sizeof(int));
|
2004-10-06 06:08:09 +00:00
|
|
|
releasePage(p);
|
2006-06-15 05:31:20 +00:00
|
|
|
//rid = Talloc(xid, sizeof(int));
|
2004-06-24 21:10:31 +00:00
|
|
|
buf = 1;
|
|
|
|
arg = 2;
|
2004-06-28 21:10:10 +00:00
|
|
|
|
|
|
|
DEBUG("A\n");
|
2004-06-24 21:10:31 +00:00
|
|
|
setToTwo = allocUpdateLogEntry(-1, xid, OPERATION_SET, rid, (void*)&arg, sizeof(int), (void*)&buf);
|
|
|
|
|
|
|
|
/* Do, undo and redo operation without updating the LSN field of the page. */
|
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
DEBUG("B\n");
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
writeRecord(xid, p, lsn, rid, &buf);
|
|
|
|
releasePage(p);
|
2004-06-28 21:10:10 +00:00
|
|
|
setToTwo->LSN = 10;
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
DEBUG("C\n");
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
doUpdate(setToTwo, p); /* PAGE LSN= 10, value = 2. */
|
|
|
|
releasePage(p);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
readRecord(xid, p, rid, &buf);
|
|
|
|
releasePage(p);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
fail_unless(buf == 2, NULL);
|
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
DEBUG("D\n");
|
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
|
|
|
|
fail_unless(10 == pageReadLSN(p), "page lsn not set correctly.");
|
2004-06-28 21:10:10 +00:00
|
|
|
|
|
|
|
setToTwo->LSN = 5;
|
|
|
|
|
2004-07-23 20:21:44 +00:00
|
|
|
undoUpdate(setToTwo, p, 8); /* Should succeed, CLR LSN is too low, but undoUpdate only checks the log entry. */
|
|
|
|
releasePage(p);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
readRecord(xid, p, rid, &buf);
|
|
|
|
releasePage(p);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
fail_unless(buf == 1, NULL);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
DEBUG("E\n");
|
2004-06-24 21:10:31 +00:00
|
|
|
redoUpdate(setToTwo);
|
|
|
|
|
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
readRecord(xid, p, rid, &buf);
|
|
|
|
releasePage(p);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
fail_unless(buf == 1, NULL);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
/* Now, simulate scenarios from normal operation:
|
|
|
|
do the operation, and update the LSN, (update happens)
|
|
|
|
then undo, and update the LSN again. (undo happens)
|
|
|
|
attempt a redo, don't update lsn (nothing happens)
|
|
|
|
|
|
|
|
Lower the LSN
|
|
|
|
attempt redo (redo succeeds)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
lsn = 0;
|
|
|
|
buf = 1;
|
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
writeRecord(xid, p, lsn, rid, &buf);
|
|
|
|
releasePage(p);
|
2004-06-28 21:10:10 +00:00
|
|
|
/* Trace of test:
|
|
|
|
|
|
|
|
PAGE LSN LOG LSN CLR LSN TYPE SUCCEED?
|
|
|
|
|
|
|
|
2 10 - do write YES (C)
|
|
|
|
10 5 8 undo write YES (D)
|
|
|
|
8 5 - redo write NO (E)
|
|
|
|
8 10 - redo write YES (F)
|
|
|
|
....... and so on.
|
|
|
|
*/
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-07-30 02:07:41 +00:00
|
|
|
/** @todo need to re-think check_operations. The test is pretty broken. */
|
2006-04-14 03:45:26 +00:00
|
|
|
Tdeinit();
|
2004-07-30 02:07:41 +00:00
|
|
|
return;
|
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
setToTwo->LSN = 10;
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
DEBUG("F\n");
|
|
|
|
redoUpdate(setToTwo);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
readRecord(xid, p, rid, &buf);
|
2004-07-30 02:07:41 +00:00
|
|
|
assert(buf == 2);
|
2004-06-24 21:10:31 +00:00
|
|
|
fail_unless(buf == 2, NULL);
|
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
DEBUG("G undo set to 2\n");
|
2004-07-23 20:21:44 +00:00
|
|
|
undoUpdate(setToTwo, p, 20); /* Succeeds -- 20 is the 'CLR' entry's lsn.*/
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-07-23 20:21:44 +00:00
|
|
|
readRecord(xid, p, rid, &buf);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
fail_unless(buf == 1, NULL);
|
2004-07-23 20:21:44 +00:00
|
|
|
releasePage(p);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
DEBUG("H don't redo set to 2\n");
|
2004-06-24 21:10:31 +00:00
|
|
|
redoUpdate(setToTwo); /* Fails */
|
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
|
|
|
|
readRecord(xid, p, rid, &buf);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
fail_unless(buf == 1, NULL);
|
|
|
|
|
2004-07-23 20:21:44 +00:00
|
|
|
writeRecord(xid, p, 0, rid, &buf); /* reset the page's LSN. */
|
2004-06-28 21:10:10 +00:00
|
|
|
|
|
|
|
DEBUG("I redo set to 2\n");
|
2004-06-24 21:10:31 +00:00
|
|
|
|
2004-07-23 20:21:44 +00:00
|
|
|
releasePage(p);
|
|
|
|
redoUpdate(setToTwo); /* Succeeds */
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, rid.page);
|
2004-07-23 20:21:44 +00:00
|
|
|
readRecord(xid, p, rid, &buf);
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
fail_unless(buf == 2, NULL);
|
2004-07-23 20:21:44 +00:00
|
|
|
releasePage(p);
|
2004-06-24 21:10:31 +00:00
|
|
|
Tdeinit();
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2004-10-02 07:29:34 +00:00
|
|
|
/**
|
|
|
|
@test check the Tprepare() call by simulating crashes.
|
|
|
|
*/
|
|
|
|
START_TEST(operation_prepare) {
|
|
|
|
|
|
|
|
/* Check this sequence prepare, action, crash, recover, read, action, abort, read again. */
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int loser = Tbegin();
|
|
|
|
int prepared = Tbegin();
|
|
|
|
int winner = Tbegin();
|
|
|
|
|
|
|
|
recordid a = Talloc(winner, sizeof(int));
|
|
|
|
recordid b = Talloc(winner, sizeof(int));
|
|
|
|
|
|
|
|
int one =1;
|
|
|
|
int two =2;
|
|
|
|
int three=3;
|
|
|
|
|
|
|
|
Tset(winner, a, &one);
|
|
|
|
Tset(winner, b, &one);
|
|
|
|
|
|
|
|
Tset(loser, a, &three);
|
|
|
|
Tset(prepared, b, &three);
|
|
|
|
|
|
|
|
Tprepare(prepared, a);
|
|
|
|
|
|
|
|
Tset(prepared, b, &two);
|
|
|
|
|
|
|
|
Tcommit(winner);
|
2006-04-14 03:45:26 +00:00
|
|
|
truncationDeinit();
|
2004-10-02 07:29:34 +00:00
|
|
|
simulateBufferManagerCrash();
|
2006-04-07 03:40:40 +00:00
|
|
|
// closeLogWriter();
|
|
|
|
LogDeinit();
|
2004-10-02 07:29:34 +00:00
|
|
|
numActiveXactions = 0;
|
|
|
|
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int in;
|
|
|
|
|
|
|
|
Tread(prepared, b, &in);
|
|
|
|
|
|
|
|
assert(in == three);
|
|
|
|
|
|
|
|
Tset(prepared, b, &two);
|
|
|
|
|
|
|
|
Tabort(prepared);
|
|
|
|
|
|
|
|
int checker = Tbegin();
|
|
|
|
|
|
|
|
Tread(checker, b, &in);
|
|
|
|
|
|
|
|
assert(in == one);
|
|
|
|
|
|
|
|
Tread(checker, a, &in);
|
|
|
|
|
|
|
|
assert(in == one);
|
|
|
|
|
|
|
|
Tcommit(checker);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
/* Check this sequence prepare, action, crash, recover, read, action, _COMMIT_, read again. */
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
loser = Tbegin();
|
|
|
|
prepared = Tbegin();
|
|
|
|
winner = Tbegin();
|
|
|
|
|
|
|
|
a = Talloc(winner, sizeof(int));
|
|
|
|
b = Talloc(winner, sizeof(int));
|
|
|
|
|
|
|
|
one =1;
|
|
|
|
two =2;
|
|
|
|
three=3;
|
|
|
|
|
|
|
|
Tset(winner, a, &one);
|
|
|
|
Tset(winner, b, &one);
|
|
|
|
|
|
|
|
Tset(loser, a, &three);
|
|
|
|
Tset(prepared, b, &three);
|
|
|
|
|
|
|
|
Tprepare(prepared, a);
|
|
|
|
|
|
|
|
Tset(prepared, b, &two);
|
|
|
|
|
|
|
|
Tcommit(winner);
|
2006-04-14 03:45:26 +00:00
|
|
|
truncationDeinit();
|
2004-10-02 07:29:34 +00:00
|
|
|
simulateBufferManagerCrash();
|
2006-04-07 03:40:40 +00:00
|
|
|
// closeLogWriter();
|
|
|
|
LogDeinit();
|
2004-10-02 07:29:34 +00:00
|
|
|
numActiveXactions = 0;
|
|
|
|
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
Tread(prepared, b, &in);
|
|
|
|
|
|
|
|
assert(in == three);
|
|
|
|
|
|
|
|
Tset(prepared, b, &two);
|
|
|
|
|
|
|
|
Tcommit(prepared);
|
|
|
|
|
|
|
|
checker = Tbegin();
|
|
|
|
|
|
|
|
Tread(checker, b, &in);
|
|
|
|
|
|
|
|
assert(in == two);
|
|
|
|
|
|
|
|
Tread(checker, a, &in);
|
|
|
|
|
|
|
|
assert(in == one);
|
|
|
|
|
|
|
|
Tcommit(checker);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
|
|
|
|
} END_TEST
|
2004-11-29 21:28:13 +00:00
|
|
|
/**
|
|
|
|
@test Runs some actions as part of a nested top action, aborts the transaction,
|
|
|
|
and checks that the result is as expected.
|
|
|
|
|
|
|
|
@todo Write a more thorough (threaded!) nested top action test.
|
2005-02-10 03:51:09 +00:00
|
|
|
|
2004-11-29 21:28:13 +00:00
|
|
|
*/
|
|
|
|
START_TEST(operation_nestedTopAction) {
|
|
|
|
|
|
|
|
printf("\nNested Top Action\n"); fflush(NULL);
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int xid= Tbegin();
|
|
|
|
int *dat;
|
2004-12-06 01:20:48 +00:00
|
|
|
//printf("W"); fflush(NULL);
|
|
|
|
dat = malloc(sizeof(int));
|
2004-11-29 21:28:13 +00:00
|
|
|
recordid rid1 = Talloc(xid, sizeof(int));
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("{%d,%d,%d}\n", rid1.page, rid1.slot, rid1.size); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
recordid rid2 = Talloc(xid, sizeof(int));
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("{%d,%d,%d}\n", rid2.page, rid2.slot, rid2.size); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
recordid rid3 = Talloc(xid, sizeof(int));
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("{%d,%d,%d}\n", rid3.page, rid3.slot, rid3.size); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
recordid rid4 = Talloc(xid, sizeof(int));
|
2004-12-06 01:20:48 +00:00
|
|
|
//printf("{%d,%d,%d}\n", rid4.page, rid4.slot, rid4.size); fflush(NULL);
|
|
|
|
// printf("E"); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
*dat = 1;
|
|
|
|
Tset(xid, rid1, dat);
|
|
|
|
*dat = 2;
|
|
|
|
Tset(xid, rid2, dat);
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("F"); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
*dat = 3;
|
|
|
|
Tset(xid, rid3, dat);
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("G"); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
*dat = 4;
|
|
|
|
Tset(xid, rid4, dat);
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("H"); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
Tcommit(xid);
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("A"); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
xid = Tbegin(); // Loser xact.
|
|
|
|
|
|
|
|
*dat = 10;
|
|
|
|
Tset(xid, rid1, dat);
|
|
|
|
|
2005-01-15 01:45:27 +00:00
|
|
|
void * handle = TbeginNestedTopAction(xid, OPERATION_NOOP, NULL, 0);
|
2004-11-29 21:28:13 +00:00
|
|
|
|
|
|
|
*dat = 20;
|
|
|
|
Tset(xid, rid2, dat);
|
|
|
|
*dat = 30;
|
|
|
|
Tset(xid, rid3, dat);
|
|
|
|
|
2005-01-15 01:45:27 +00:00
|
|
|
TendNestedTopAction(xid, handle);
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("B"); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
*dat = 40;
|
|
|
|
|
|
|
|
Tset(xid, rid4, dat);
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
int dat1;
|
|
|
|
int dat2;
|
|
|
|
int dat3;
|
|
|
|
int dat4;
|
2004-12-06 01:20:48 +00:00
|
|
|
// printf("C"); fflush(NULL);
|
2004-11-29 21:28:13 +00:00
|
|
|
Tread(xid, rid1, &dat1);
|
|
|
|
Tread(xid, rid2, &dat2);
|
|
|
|
Tread(xid, rid3, &dat3);
|
|
|
|
Tread(xid, rid4, &dat4);
|
|
|
|
|
|
|
|
assert(dat1 == 1);
|
|
|
|
assert(dat2 == 20);
|
|
|
|
assert(dat3 == 30);
|
|
|
|
assert(dat4 == 4);
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
Tdeinit();
|
|
|
|
|
|
|
|
} END_TEST
|
|
|
|
|
2004-10-02 07:29:34 +00:00
|
|
|
/**
|
|
|
|
@test make sure the TinstantSet() operation works as expected during normal operation.
|
|
|
|
@todo need to write test for TinstantSet() for the recovery case...
|
|
|
|
*/
|
|
|
|
|
|
|
|
START_TEST(operation_instant_set) {
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
recordid rid = Talloc(xid, sizeof(int)); /** @todo probably need an immediate version of TpageAlloc... */
|
|
|
|
int one = 1;
|
|
|
|
int two = 2;
|
|
|
|
int three = 3;
|
|
|
|
Tset(xid, rid, &one);
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
TinstantSet(xid, rid, &two);
|
|
|
|
|
|
|
|
Tset(xid, rid, &three);
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
Tread(xid, rid, &three);
|
|
|
|
|
|
|
|
assert(two == three);
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
Tread(xid, rid, &three);
|
|
|
|
|
|
|
|
assert(two == three);
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} END_TEST
|
|
|
|
|
2004-12-03 00:27:47 +00:00
|
|
|
START_TEST(operation_set_range) {
|
|
|
|
printf("Set Range");
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
int buf1[20];
|
|
|
|
int buf2[20];
|
|
|
|
|
|
|
|
int range[20];
|
|
|
|
|
|
|
|
recordid rid = Talloc(xid, sizeof(int) * 20);
|
|
|
|
|
|
|
|
for(int i = 0; i < 20; i++) {
|
|
|
|
buf1[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tset(xid, rid, buf1);
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
Tread(xid, rid, buf2);
|
|
|
|
for(int i = 0; i < 20; i++) {
|
|
|
|
assert(buf2[i] == i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < 5; i++) {
|
|
|
|
range[i] = 100 + i;
|
|
|
|
}
|
|
|
|
|
|
|
|
TsetRange(xid, rid, sizeof(int) * 10, sizeof(int) * 5, range);
|
|
|
|
// Check forward action
|
|
|
|
Tread(xid, rid, buf2);
|
|
|
|
|
|
|
|
for(int i = 0; i < 20; i++) {
|
|
|
|
if(i < 10 || i >= 15) {
|
|
|
|
assert(buf2[i] == i);
|
|
|
|
} else {
|
|
|
|
assert(buf2[i] == 100 + i - 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
Tread(xid, rid, buf2);
|
|
|
|
//Check undo.
|
|
|
|
for(int i = 0; i < 20; i++) {
|
|
|
|
assert(buf2[i] == i);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
2005-02-10 03:51:09 +00:00
|
|
|
Tdeinit();
|
|
|
|
|
2004-12-03 00:27:47 +00:00
|
|
|
} END_TEST
|
2004-12-06 01:20:48 +00:00
|
|
|
|
|
|
|
START_TEST(operation_alloc_test) {
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
recordid rid1 = Talloc(xid, 100);
|
|
|
|
Tcommit(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
recordid rid2 = Talloc(xid, 100);
|
|
|
|
Tcommit(xid);
|
|
|
|
|
2006-08-11 19:31:42 +00:00
|
|
|
printf("rid1={%ld,%d,%ld} rid2={%ld,%d,%ld}\n",
|
|
|
|
(int64_t)rid1.page, rid1.slot, (int64_t)rid1.size,
|
|
|
|
(int64_t)rid2.page, rid2.slot, (int64_t)rid2.size);
|
2004-12-06 01:20:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
2004-12-03 00:27:47 +00:00
|
|
|
#define ARRAY_LIST_CHECK_ITER 10000
|
2004-10-06 06:08:09 +00:00
|
|
|
START_TEST(operation_array_list) {
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
recordid rid = TarrayListAlloc(xid, 4, 2, sizeof(int));
|
2004-10-02 07:29:34 +00:00
|
|
|
|
2004-12-03 00:27:47 +00:00
|
|
|
TarrayListExtend(xid, rid, ARRAY_LIST_CHECK_ITER);
|
2004-10-06 06:08:09 +00:00
|
|
|
|
|
|
|
printf("commit");
|
|
|
|
fflush(stdout);
|
|
|
|
Tcommit(xid);
|
|
|
|
printf("done1\n");
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
recordid rid2;
|
|
|
|
rid2.page = rid.page;
|
|
|
|
rid2.slot = 0;
|
|
|
|
rid2.size = sizeof(int);
|
|
|
|
|
2004-12-03 00:27:47 +00:00
|
|
|
for(int i = 0; i < ARRAY_LIST_CHECK_ITER; i++) {
|
2004-10-06 06:08:09 +00:00
|
|
|
rid2.slot = i;
|
|
|
|
Tset(xid, rid2, &i);
|
|
|
|
}
|
|
|
|
|
2004-12-03 00:27:47 +00:00
|
|
|
for(int i = 0; i < ARRAY_LIST_CHECK_ITER; i++) {
|
2004-10-06 06:08:09 +00:00
|
|
|
rid2.slot = i;
|
|
|
|
int j;
|
|
|
|
Tread(xid, rid2, &j);
|
|
|
|
assert(i == j);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("commit");
|
|
|
|
fflush(stdout);
|
|
|
|
Tcommit(xid);
|
|
|
|
printf("-done2\n");
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
2004-12-03 00:27:47 +00:00
|
|
|
for(int i = 0; i < ARRAY_LIST_CHECK_ITER; i++) {
|
2004-10-06 06:08:09 +00:00
|
|
|
int j = 0-i;
|
|
|
|
rid2.slot = i;
|
|
|
|
Tset(xid, rid2, &j);
|
|
|
|
}
|
|
|
|
|
2004-12-03 00:27:47 +00:00
|
|
|
for(int i = 0; i < ARRAY_LIST_CHECK_ITER; i++) {
|
2004-10-06 06:08:09 +00:00
|
|
|
rid2.slot = i;
|
|
|
|
int j = 0-i;
|
|
|
|
int k;
|
|
|
|
Tread(xid, rid2, &k);
|
|
|
|
assert(k == j);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("abort");
|
|
|
|
fflush(stdout);
|
|
|
|
Tabort(xid);
|
|
|
|
printf("-done\n");
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
2004-12-03 00:27:47 +00:00
|
|
|
for(int i = 0; i < ARRAY_LIST_CHECK_ITER; i++) {
|
2004-10-06 06:08:09 +00:00
|
|
|
rid2.slot = i;
|
|
|
|
int j;
|
|
|
|
Tread(xid, rid2, &j);
|
|
|
|
assert(i == j);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("commit");
|
|
|
|
fflush(stdout);
|
|
|
|
Tcommit(xid);
|
|
|
|
printf("done3\n");
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
|
|
|
|
} END_TEST
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Add suite declarations here
|
|
|
|
*/
|
|
|
|
Suite * check_suite(void) {
|
|
|
|
Suite *s = suite_create("operations");
|
|
|
|
/* Begin a new test */
|
2005-03-13 02:24:01 +00:00
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
TCase *tc = tcase_create("operations_simple");
|
2005-03-13 02:24:01 +00:00
|
|
|
tcase_set_timeout(tc, 0); // disable timeouts
|
2004-06-24 21:10:31 +00:00
|
|
|
|
|
|
|
/* Sub tests are added, one per line, here */
|
|
|
|
tcase_add_test(tc, operation_physical_do_undo);
|
2004-11-29 21:28:13 +00:00
|
|
|
tcase_add_test(tc, operation_nestedTopAction);
|
2004-10-02 07:29:34 +00:00
|
|
|
tcase_add_test(tc, operation_instant_set);
|
2004-12-03 00:27:47 +00:00
|
|
|
tcase_add_test(tc, operation_set_range);
|
2006-04-07 03:40:40 +00:00
|
|
|
if(loggerType != LOG_TO_MEMORY) {
|
|
|
|
tcase_add_test(tc, operation_prepare);
|
|
|
|
}
|
2004-12-06 01:20:48 +00:00
|
|
|
tcase_add_test(tc, operation_alloc_test);
|
2004-10-06 06:08:09 +00:00
|
|
|
tcase_add_test(tc, operation_array_list);
|
2004-06-24 21:10:31 +00:00
|
|
|
/* --------------------------------------------- */
|
|
|
|
tcase_add_checked_fixture(tc, setup, teardown);
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "../check_setup.h"
|