Support for nested top actions, with simple unit test. (Haven't tested for thread safety yet.)
This commit is contained in:
parent
646f9dfca9
commit
ded5c92c9d
8 changed files with 282 additions and 23 deletions
|
@ -49,15 +49,15 @@ project.menu.need.terminal=0
|
||||||
|
|
||||||
project.configure.options=
|
project.configure.options=
|
||||||
anjuta.program.arguments=
|
anjuta.program.arguments=
|
||||||
preferences.build.option.jobs=0
|
preferences.build.option.jobs=2
|
||||||
preferences.build.option.silent=0
|
preferences.build.option.silent=1
|
||||||
preferences.build.option.autosave=0
|
preferences.build.option.autosave=1
|
||||||
preferences.make=make
|
preferences.make=make
|
||||||
preferences.build.option.keep.going=1
|
preferences.build.option.keep.going=1
|
||||||
preferences.build.option.warn.undef=0
|
preferences.build.option.warn.undef=0
|
||||||
preferences.autoformat.custom.style= -i8 -sc -bli0 -bl0 -cbi0 -ss
|
preferences.autoformat.custom.style= -i8 -sc -bli0 -bl0 -cbi0 -ss
|
||||||
preferences.indent.opening=0
|
preferences.indent.opening=0
|
||||||
preferences.autoformat.disable=0
|
preferences.autoformat.disable=1
|
||||||
preferences.indent.automatic=1
|
preferences.indent.automatic=1
|
||||||
preferences.use.tabs=1
|
preferences.use.tabs=1
|
||||||
preferences.indent.size=2
|
preferences.indent.size=2
|
||||||
|
|
36
lladd.pws
36
lladd.pws
|
@ -11,13 +11,13 @@ filter.file.ignore.hidden=0
|
||||||
filter.dir.ignore.hidden=0
|
filter.dir.ignore.hidden=0
|
||||||
|
|
||||||
[filenumbers]
|
[filenumbers]
|
||||||
0=43
|
0=71
|
||||||
1=33
|
1=97
|
||||||
2=340
|
2=126
|
||||||
3=1
|
3=155
|
||||||
4=312
|
4=351
|
||||||
5=510
|
5=67
|
||||||
6=71
|
6=56
|
||||||
7=1
|
7=1
|
||||||
8=63
|
8=63
|
||||||
9=1
|
9=1
|
||||||
|
@ -51,11 +51,13 @@ filter.dir.ignore.hidden=0
|
||||||
17=
|
17=
|
||||||
|
|
||||||
[filelist]
|
[filelist]
|
||||||
0=/home/sears/lladd/src/lladd/operations/naiveLinearHash.c
|
0=/home/sears/lladd/lladd/logger/logger2.h
|
||||||
1=/home/sears/lladd/lladd/operations/naiveLinearHash.h
|
1=/home/sears/lladd/src/lladd/transactional2.c
|
||||||
2=/home/sears/lladd/src/lladd/operations/arrayList.c
|
2=/home/sears/lladd/src/lladd/operations.c
|
||||||
3=/home/sears/lladd/test/lladd/check_linearHash.c
|
3=/home/sears/lladd/lladd/operations.h
|
||||||
4=/home/sears/lladd/src/lladd/operations/linearHash.c
|
4=/home/sears/lladd/test/lladd/check_operations.c
|
||||||
|
5=/home/sears/lladd/lladd/operations/nestedTopActions.h
|
||||||
|
6=/home/sears/lladd/src/lladd/operations/nestedTopActions.c
|
||||||
|
|
||||||
[Project Tree]
|
[Project Tree]
|
||||||
0=0
|
0=0
|
||||||
|
@ -71,11 +73,11 @@ filter.dir.ignore.hidden=0
|
||||||
[File Tree]
|
[File Tree]
|
||||||
0=0
|
0=0
|
||||||
1=0:6
|
1=0:6
|
||||||
2=0:6:2
|
2=0:6:1
|
||||||
3=0:9
|
3=0:6:2
|
||||||
4=0:9:4
|
4=0:9
|
||||||
5=0:9:4:3
|
5=0:9:4
|
||||||
6=0:9:4:4
|
6=0:9:4:3
|
||||||
7=0:10
|
7=0:10
|
||||||
8=0:10:5
|
8=0:10:5
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,8 @@ typedef struct {
|
||||||
#include "operations/arrayList.h"
|
#include "operations/arrayList.h"
|
||||||
#include "operations/linearHash.h"
|
#include "operations/linearHash.h"
|
||||||
#include "operations/naiveLinearHash.h"
|
#include "operations/naiveLinearHash.h"
|
||||||
|
#include "operations/nestedTopActions.h"
|
||||||
|
|
||||||
extern Operation operationsTable[]; /* [MAX_OPERATIONS]; memset somewhere */
|
extern Operation operationsTable[]; /* [MAX_OPERATIONS]; memset somewhere */
|
||||||
|
|
||||||
/** Performs an operation during normal execution.
|
/** Performs an operation during normal execution.
|
||||||
|
|
66
lladd/operations/nestedTopActions.h
Normal file
66
lladd/operations/nestedTopActions.h
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/*---
|
||||||
|
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.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* function definitions for increment
|
||||||
|
*
|
||||||
|
* Increment provides an example of a logical operation that does not
|
||||||
|
* require any extra logging information, and (could someday) support
|
||||||
|
* reordering.
|
||||||
|
*
|
||||||
|
* @see decrement.h
|
||||||
|
*
|
||||||
|
* @ingroup OPERATIONS
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __NESTED_TOP_ACTIONS_H__
|
||||||
|
#define __NESTED_TOP_ACTIONS_H__
|
||||||
|
|
||||||
|
#include <lladd/operations.h>
|
||||||
|
void initNestedTopActions();
|
||||||
|
void TbeginNestedTopAction(int xid);
|
||||||
|
lsn_t TendNestedTopAction(int xid);
|
||||||
|
#endif
|
|
@ -10,6 +10,6 @@ liblladd_a_SOURCES=crc32.c common.c stats.c io.c bufferManager.c linkedlist.c op
|
||||||
operations/increment.c operations/prepare.c operations/set.c \
|
operations/increment.c operations/prepare.c operations/set.c \
|
||||||
operations/alloc.c operations/noop.c operations/instantSet.c \
|
operations/alloc.c operations/noop.c operations/instantSet.c \
|
||||||
page/slotted.c operations/lladdhash.c page/header.c page/fixed.c \
|
page/slotted.c operations/lladdhash.c page/header.c page/fixed.c \
|
||||||
operations/arrayList.c hash.c operations/linearHash.c operations/naiveLinearHash.c
|
operations/arrayList.c hash.c operations/linearHash.c operations/naiveLinearHash.c \
|
||||||
|
operations/nestedTopActions.c
|
||||||
AM_CFLAGS= -g -Wall -pedantic -std=gnu99
|
AM_CFLAGS= -g -Wall -pedantic -std=gnu99
|
||||||
|
|
||||||
|
|
117
src/lladd/operations/nestedTopActions.c
Normal file
117
src/lladd/operations/nestedTopActions.c
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
/*---
|
||||||
|
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.
|
||||||
|
---*/
|
||||||
|
/**********************************************
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Decrements the given reference by one
|
||||||
|
*********************************************/
|
||||||
|
#include <lladd/transactional.h>
|
||||||
|
#include <lladd/common.h>
|
||||||
|
#include <lladd/operations/nestedTopActions.h>
|
||||||
|
#include <lladd/logger/logger2.h>
|
||||||
|
#include "../logger/logWriter.h"
|
||||||
|
#include <pbl/pbl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
/** @todo Remove extern declaration of transactional_2_mutex from nestedTopActions.c */
|
||||||
|
extern pthread_mutex_t transactional_2_mutex;
|
||||||
|
|
||||||
|
|
||||||
|
/*#include <lladd/bufferManager.h>*/
|
||||||
|
|
||||||
|
extern TransactionLog XactionTable[];
|
||||||
|
|
||||||
|
pblHashTable_t * nestedTopActions = NULL;
|
||||||
|
/** @todo this really should be set somewhere globally. */
|
||||||
|
static recordid NULLRID;
|
||||||
|
|
||||||
|
void initNestedTopActions() {
|
||||||
|
nestedTopActions = pblHtCreate();
|
||||||
|
NULLRID.page = 0;
|
||||||
|
NULLRID.slot = 0;
|
||||||
|
NULLRID.size = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TbeginNestedTopAction(int xid) {
|
||||||
|
lsn_t * prevLSN = malloc(sizeof(lsn_t));
|
||||||
|
pthread_mutex_lock(&transactional_2_mutex);
|
||||||
|
*prevLSN = XactionTable[xid].prevLSN;
|
||||||
|
pblHtInsert(nestedTopActions, &xid, sizeof(int), prevLSN);
|
||||||
|
pthread_mutex_unlock(&transactional_2_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Call this function at the end of a nested top action.
|
||||||
|
|
||||||
|
@return the lsn of the CLR. Most users (everyone?) will ignore this.
|
||||||
|
|
||||||
|
@todo LogCLR()'s API is useless. Make it private, and implement a better
|
||||||
|
public version. (Then rewrite TendNestedTopAction)
|
||||||
|
*/
|
||||||
|
lsn_t TendNestedTopAction(int xid) {
|
||||||
|
|
||||||
|
pthread_mutex_lock(&transactional_2_mutex);
|
||||||
|
|
||||||
|
lsn_t * prevLSN = pblHtLookup(nestedTopActions, &xid, sizeof(int));
|
||||||
|
|
||||||
|
// This action wasn't really undone -- This is a nested top action!
|
||||||
|
lsn_t undoneLSN = XactionTable[xid].prevLSN;
|
||||||
|
recordid undoneRID = NULLRID; // Not correct, but this field is unused anyway. ;)
|
||||||
|
|
||||||
|
// Write a CLR.
|
||||||
|
LogEntry * e = allocCLRLogEntry(-1, xid, undoneLSN, undoneRID, *prevLSN);
|
||||||
|
writeLogEntry(e);
|
||||||
|
|
||||||
|
// Ensure that the next action in this transaction points to the CLR.
|
||||||
|
XactionTable[xid].prevLSN = e->LSN;
|
||||||
|
|
||||||
|
DEBUG("NestedTopAction CLR %d, LSN: %ld type: %ld (undoing: %ld, next to undo: %ld)\n", e->xid,
|
||||||
|
(long int)e->LSN, (long int)e->type, (long int)undone->LSN, (long int)undone->prevLSN);
|
||||||
|
|
||||||
|
lsn_t ret = e->LSN;
|
||||||
|
free(e);
|
||||||
|
pthread_mutex_unlock(&transactional_2_mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -79,6 +79,7 @@ int Tinit() {
|
||||||
openLogWriter();
|
openLogWriter();
|
||||||
|
|
||||||
pageOperationsInit();
|
pageOperationsInit();
|
||||||
|
initNestedTopActions();
|
||||||
ThashInit();
|
ThashInit();
|
||||||
|
|
||||||
InitiateRecovery();
|
InitiateRecovery();
|
||||||
|
|
|
@ -325,6 +325,76 @@ START_TEST(operation_prepare) {
|
||||||
Tdeinit();
|
Tdeinit();
|
||||||
|
|
||||||
} END_TEST
|
} END_TEST
|
||||||
|
/**
|
||||||
|
@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.
|
||||||
|
*/
|
||||||
|
START_TEST(operation_nestedTopAction) {
|
||||||
|
|
||||||
|
printf("\nNested Top Action\n"); fflush(NULL);
|
||||||
|
|
||||||
|
Tinit();
|
||||||
|
|
||||||
|
int xid= Tbegin();
|
||||||
|
int *dat;
|
||||||
|
dat == malloc(sizeof(int));
|
||||||
|
recordid rid1 = Talloc(xid, sizeof(int));
|
||||||
|
recordid rid2 = Talloc(xid, sizeof(int));
|
||||||
|
recordid rid3 = Talloc(xid, sizeof(int));
|
||||||
|
recordid rid4 = Talloc(xid, sizeof(int));
|
||||||
|
*dat = 1;
|
||||||
|
Tset(xid, rid1, dat);
|
||||||
|
*dat = 2;
|
||||||
|
Tset(xid, rid2, dat);
|
||||||
|
*dat = 3;
|
||||||
|
Tset(xid, rid3, dat);
|
||||||
|
*dat = 4;
|
||||||
|
Tset(xid, rid4, dat);
|
||||||
|
Tcommit(xid);
|
||||||
|
|
||||||
|
xid = Tbegin(); // Loser xact.
|
||||||
|
|
||||||
|
*dat = 10;
|
||||||
|
Tset(xid, rid1, dat);
|
||||||
|
|
||||||
|
TbeginNestedTopAction(xid);
|
||||||
|
|
||||||
|
*dat = 20;
|
||||||
|
Tset(xid, rid2, dat);
|
||||||
|
*dat = 30;
|
||||||
|
Tset(xid, rid3, dat);
|
||||||
|
|
||||||
|
TendNestedTopAction(xid);
|
||||||
|
|
||||||
|
*dat = 40;
|
||||||
|
|
||||||
|
Tset(xid, rid4, dat);
|
||||||
|
|
||||||
|
Tabort(xid);
|
||||||
|
|
||||||
|
xid = Tbegin();
|
||||||
|
int dat1;
|
||||||
|
int dat2;
|
||||||
|
int dat3;
|
||||||
|
int dat4;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@test make sure the TinstantSet() operation works as expected during normal operation.
|
@test make sure the TinstantSet() operation works as expected during normal operation.
|
||||||
@todo need to write test for TinstantSet() for the recovery case...
|
@todo need to write test for TinstantSet() for the recovery case...
|
||||||
|
@ -470,6 +540,7 @@ Suite * check_suite(void) {
|
||||||
|
|
||||||
/* Sub tests are added, one per line, here */
|
/* Sub tests are added, one per line, here */
|
||||||
tcase_add_test(tc, operation_physical_do_undo);
|
tcase_add_test(tc, operation_physical_do_undo);
|
||||||
|
tcase_add_test(tc, operation_nestedTopAction);
|
||||||
tcase_add_test(tc, operation_instant_set);
|
tcase_add_test(tc, operation_instant_set);
|
||||||
tcase_add_test(tc, operation_prepare);
|
tcase_add_test(tc, operation_prepare);
|
||||||
tcase_add_test(tc, operation_array_list);
|
tcase_add_test(tc, operation_array_list);
|
||||||
|
|
Loading…
Reference in a new issue