Commit e339d265 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #2262 refs[t:2262] Add DB_INHERIT_ISOLATION flag to TXN_BEGIN


git-svn-id: file:///svn/toku/tokudb@16621 c7de825b-a66e-492c-adef-691d508d4ae1
parent 056b47bd
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
/*stdio is needed for the FILE* in db->verify*/ /*stdio is needed for the FILE* in db->verify*/
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -163,6 +164,7 @@ typedef enum { ...@@ -163,6 +164,7 @@ typedef enum {
#define DB_TXN_WRITE_NOSYNC 524288 #define DB_TXN_WRITE_NOSYNC 524288
#define DB_TXN_NOWAIT 2048 #define DB_TXN_NOWAIT 2048
#define DB_TXN_SYNC 4096 #define DB_TXN_SYNC 4096
#define DB_INHERIT_ISOLATION 1
#endif #endif
/* TOKUDB specific error codes */ /* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000 #define TOKUDB_OUT_OF_LOCKS -100000
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
/*stdio is needed for the FILE* in db->verify*/ /*stdio is needed for the FILE* in db->verify*/
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -165,6 +166,7 @@ typedef enum { ...@@ -165,6 +166,7 @@ typedef enum {
#define DB_TXN_WRITE_NOSYNC 268435456 #define DB_TXN_WRITE_NOSYNC 268435456
#define DB_TXN_NOWAIT 4096 #define DB_TXN_NOWAIT 4096
#define DB_TXN_SYNC 8192 #define DB_TXN_SYNC 8192
#define DB_INHERIT_ISOLATION 1
#endif #endif
/* TOKUDB specific error codes */ /* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000 #define TOKUDB_OUT_OF_LOCKS -100000
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
/*stdio is needed for the FILE* in db->verify*/ /*stdio is needed for the FILE* in db->verify*/
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -132,7 +133,6 @@ typedef enum { ...@@ -132,7 +133,6 @@ typedef enum {
#define DB_INIT_MPOOL 65536 #define DB_INIT_MPOOL 65536
#define DB_CLOSE_DONT_TRIM_LOG 1048576 #define DB_CLOSE_DONT_TRIM_LOG 1048576
#define DB_INIT_TXN 262144 #define DB_INIT_TXN 262144
#define DB_READ_UNCOMMITTED 67108864
#define DB_KEYEXIST -30996 #define DB_KEYEXIST -30996
#define DB_LOCK_DEADLOCK -30995 #define DB_LOCK_DEADLOCK -30995
#define DB_LOCK_NOTGRANTED -30994 #define DB_LOCK_NOTGRANTED -30994
...@@ -166,6 +166,8 @@ typedef enum { ...@@ -166,6 +166,8 @@ typedef enum {
#define DB_TXN_WRITE_NOSYNC 1024 #define DB_TXN_WRITE_NOSYNC 1024
#define DB_TXN_NOWAIT 8192 #define DB_TXN_NOWAIT 8192
#define DB_TXN_SYNC 16384 #define DB_TXN_SYNC 16384
#define DB_READ_UNCOMMITTED 67108864
#define DB_INHERIT_ISOLATION 1
#endif #endif
/* TOKUDB specific error codes */ /* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000 #define TOKUDB_OUT_OF_LOCKS -100000
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
/*stdio is needed for the FILE* in db->verify*/ /*stdio is needed for the FILE* in db->verify*/
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -132,7 +133,6 @@ typedef enum { ...@@ -132,7 +133,6 @@ typedef enum {
#define DB_INIT_MPOOL 131072 #define DB_INIT_MPOOL 131072
#define DB_CLOSE_DONT_TRIM_LOG 1048576 #define DB_CLOSE_DONT_TRIM_LOG 1048576
#define DB_INIT_TXN 524288 #define DB_INIT_TXN 524288
#define DB_READ_UNCOMMITTED 134217728
#define DB_KEYEXIST -30996 #define DB_KEYEXIST -30996
#define DB_LOCK_DEADLOCK -30995 #define DB_LOCK_DEADLOCK -30995
#define DB_LOCK_NOTGRANTED -30994 #define DB_LOCK_NOTGRANTED -30994
...@@ -166,6 +166,8 @@ typedef enum { ...@@ -166,6 +166,8 @@ typedef enum {
#define DB_TXN_WRITE_NOSYNC 2048 #define DB_TXN_WRITE_NOSYNC 2048
#define DB_TXN_NOWAIT 16384 #define DB_TXN_NOWAIT 16384
#define DB_TXN_SYNC 32768 #define DB_TXN_SYNC 32768
#define DB_READ_UNCOMMITTED 134217728
#define DB_INHERIT_ISOLATION 1
#endif #endif
/* TOKUDB specific error codes */ /* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000 #define TOKUDB_OUT_OF_LOCKS -100000
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
/*stdio is needed for the FILE* in db->verify*/ /*stdio is needed for the FILE* in db->verify*/
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -132,7 +133,6 @@ typedef enum { ...@@ -132,7 +133,6 @@ typedef enum {
#define DB_INIT_MPOOL 524288 #define DB_INIT_MPOOL 524288
#define DB_CLOSE_DONT_TRIM_LOG 1048576 #define DB_CLOSE_DONT_TRIM_LOG 1048576
#define DB_INIT_TXN 2097152 #define DB_INIT_TXN 2097152
#define DB_READ_UNCOMMITTED 134217728
#define DB_KEYEXIST -30996 #define DB_KEYEXIST -30996
#define DB_LOCK_DEADLOCK -30995 #define DB_LOCK_DEADLOCK -30995
#define DB_LOCK_NOTGRANTED -30994 #define DB_LOCK_NOTGRANTED -30994
...@@ -168,6 +168,8 @@ typedef enum { ...@@ -168,6 +168,8 @@ typedef enum {
#define DB_TXN_WRITE_NOSYNC 4096 #define DB_TXN_WRITE_NOSYNC 4096
#define DB_TXN_NOWAIT 1024 #define DB_TXN_NOWAIT 1024
#define DB_TXN_SYNC 16384 #define DB_TXN_SYNC 16384
#define DB_READ_UNCOMMITTED 134217728
#define DB_INHERIT_ISOLATION 1
#endif #endif
/* TOKUDB specific error codes */ /* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000 #define TOKUDB_OUT_OF_LOCKS -100000
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#define VISIBLE "__attribute__((__visibility__(\"default\")))" #define VISIBLE "__attribute__((__visibility__(\"default\")))"
...@@ -28,6 +29,19 @@ void print_db_notices (void) { ...@@ -28,6 +29,19 @@ void print_db_notices (void) {
#endif #endif
#define dodefine(name) printf("#define %s %d\n", #name, name) #define dodefine(name) printf("#define %s %d\n", #name, name)
#define dodefine_track(flags, name) do {assert((flags & name) != name); \
flags |= (name); \
printf("#define %s %d\n", #name, name);} while (0)
#define dodefine_from_track(flags, name) do { \
uint32_t which; \
uint32_t bit; \
for (which = 0; which < 32; which++) { \
bit = 1U << which; \
if (!(flags & bit)) break; \
} \
assert(which < 32); \
printf("#define %s %d\n", #name, bit); \
} while (0)
enum { enum {
TOKUDB_OUT_OF_LOCKS = -100000, TOKUDB_OUT_OF_LOCKS = -100000,
...@@ -86,9 +100,6 @@ void print_defines (void) { ...@@ -86,9 +100,6 @@ void print_defines (void) {
printf("#define DB_CLOSE_DONT_TRIM_LOG 1048576\n"); // tokudb printf("#define DB_CLOSE_DONT_TRIM_LOG 1048576\n"); // tokudb
dodefine(DB_INIT_TXN); dodefine(DB_INIT_TXN);
#ifdef DB_READ_UNCOMMITTED
dodefine(DB_READ_UNCOMMITTED);
#endif
//dodefine(DB_KEYEMPTY); /// KEYEMPTY is no longer used. We just use DB_NOTFOUND //dodefine(DB_KEYEMPTY); /// KEYEMPTY is no longer used. We just use DB_NOTFOUND
dodefine(DB_KEYEXIST); dodefine(DB_KEYEXIST);
dodefine(DB_LOCK_DEADLOCK); dodefine(DB_LOCK_DEADLOCK);
...@@ -134,10 +145,18 @@ void print_defines (void) { ...@@ -134,10 +145,18 @@ void print_defines (void) {
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3 #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
dodefine(DB_LOG_AUTOREMOVE); dodefine(DB_LOG_AUTOREMOVE);
#endif #endif
dodefine(DB_TXN_WRITE_NOSYNC);
dodefine(DB_TXN_NOWAIT);
dodefine(DB_TXN_SYNC);
{
//Txn begin/commit flags
uint32_t txn_flags = 0;
dodefine_track(txn_flags, DB_TXN_WRITE_NOSYNC);
dodefine_track(txn_flags, DB_TXN_NOWAIT);
dodefine_track(txn_flags, DB_TXN_SYNC);
#ifdef DB_READ_UNCOMMITTED
dodefine_track(txn_flags, DB_READ_UNCOMMITTED);
#endif
dodefine_from_track(txn_flags, DB_INHERIT_ISOLATION);
}
printf("#endif\n"); printf("#endif\n");
...@@ -288,6 +307,7 @@ int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__un ...@@ -288,6 +307,7 @@ int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__un
printf("#include <sys/types.h>\n"); printf("#include <sys/types.h>\n");
printf("/*stdio is needed for the FILE* in db->verify*/\n"); printf("/*stdio is needed for the FILE* in db->verify*/\n");
printf("#include <stdio.h>\n"); printf("#include <stdio.h>\n");
printf("#include <stdint.h>\n");
//printf("#include <inttypes.h>\n"); //printf("#include <inttypes.h>\n");
printf("#if defined(__cplusplus)\nextern \"C\" {\n#endif\n"); printf("#if defined(__cplusplus)\nextern \"C\" {\n#endif\n");
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
/*stdio is needed for the FILE* in db->verify*/ /*stdio is needed for the FILE* in db->verify*/
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -132,7 +133,6 @@ typedef enum { ...@@ -132,7 +133,6 @@ typedef enum {
#define DB_INIT_MPOOL 524288 #define DB_INIT_MPOOL 524288
#define DB_CLOSE_DONT_TRIM_LOG 1048576 #define DB_CLOSE_DONT_TRIM_LOG 1048576
#define DB_INIT_TXN 2097152 #define DB_INIT_TXN 2097152
#define DB_READ_UNCOMMITTED 134217728
#define DB_KEYEXIST -30996 #define DB_KEYEXIST -30996
#define DB_LOCK_DEADLOCK -30995 #define DB_LOCK_DEADLOCK -30995
#define DB_LOCK_NOTGRANTED -30994 #define DB_LOCK_NOTGRANTED -30994
...@@ -168,6 +168,8 @@ typedef enum { ...@@ -168,6 +168,8 @@ typedef enum {
#define DB_TXN_WRITE_NOSYNC 4096 #define DB_TXN_WRITE_NOSYNC 4096
#define DB_TXN_NOWAIT 1024 #define DB_TXN_NOWAIT 1024
#define DB_TXN_SYNC 16384 #define DB_TXN_SYNC 16384
#define DB_READ_UNCOMMITTED 134217728
#define DB_INHERIT_ISOLATION 1
#endif #endif
/* TOKUDB specific error codes */ /* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000 #define TOKUDB_OUT_OF_LOCKS -100000
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
/*stdio is needed for the FILE* in db->verify*/ /*stdio is needed for the FILE* in db->verify*/
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
...@@ -132,7 +133,6 @@ typedef enum { ...@@ -132,7 +133,6 @@ typedef enum {
#define DB_INIT_MPOOL 524288 #define DB_INIT_MPOOL 524288
#define DB_CLOSE_DONT_TRIM_LOG 1048576 #define DB_CLOSE_DONT_TRIM_LOG 1048576
#define DB_INIT_TXN 2097152 #define DB_INIT_TXN 2097152
#define DB_READ_UNCOMMITTED 134217728
#define DB_KEYEXIST -30996 #define DB_KEYEXIST -30996
#define DB_LOCK_DEADLOCK -30995 #define DB_LOCK_DEADLOCK -30995
#define DB_LOCK_NOTGRANTED -30994 #define DB_LOCK_NOTGRANTED -30994
...@@ -168,6 +168,8 @@ typedef enum { ...@@ -168,6 +168,8 @@ typedef enum {
#define DB_TXN_WRITE_NOSYNC 4096 #define DB_TXN_WRITE_NOSYNC 4096
#define DB_TXN_NOWAIT 1024 #define DB_TXN_NOWAIT 1024
#define DB_TXN_SYNC 16384 #define DB_TXN_SYNC 16384
#define DB_READ_UNCOMMITTED 134217728
#define DB_INHERIT_ISOLATION 1
#endif #endif
/* TOKUDB specific error codes */ /* TOKUDB specific error codes */
#define TOKUDB_OUT_OF_LOCKS -100000 #define TOKUDB_OUT_OF_LOCKS -100000
......
...@@ -1702,14 +1702,27 @@ static int toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t f ...@@ -1702,14 +1702,27 @@ static int toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t f
if (!(env->i->open_flags & DB_INIT_TXN)) return toku_ydb_do_error(env, EINVAL, "Environment does not have transactions enabled\n"); if (!(env->i->open_flags & DB_INIT_TXN)) return toku_ydb_do_error(env, EINVAL, "Environment does not have transactions enabled\n");
u_int32_t txn_flags = 0; u_int32_t txn_flags = 0;
txn_flags |= DB_TXN_NOWAIT; //We do not support blocking locks. txn_flags |= DB_TXN_NOWAIT; //We do not support blocking locks.
if (internal && stxn) { uint32_t child_isolation_flags = 0; //TODO: #2126 DB_READ_COMMITTED should be added here once supported.
uint32_t parent_isolation_flags = db_txn_struct_i(stxn)->flags & (DB_READ_UNCOMMITTED); //TODO: #2126 DB_READ_COMMITTED should be added here once supported. uint32_t parent_isolation_flags = 0;
flags |= parent_isolation_flags; int inherit = 0;
int set_isolation = 0;
if (stxn) {
parent_isolation_flags = db_txn_struct_i(stxn)->flags & (DB_READ_UNCOMMITTED); //TODO: #2126 DB_READ_COMMITTED should be added here once supported.
if (internal || flags&DB_INHERIT_ISOLATION) {
flags &= ~DB_INHERIT_ISOLATION;
inherit = 1;
set_isolation = 1;
child_isolation_flags = parent_isolation_flags;
}
} }
if (flags&DB_READ_UNCOMMITTED) { if (flags&DB_READ_UNCOMMITTED) {
txn_flags |= DB_READ_UNCOMMITTED; if (set_isolation)
return toku_ydb_do_error(env, EINVAL, "Cannot set isolation two different ways in DB_ENV->txn_begin\n");
set_isolation = 1;
child_isolation_flags |= DB_READ_UNCOMMITTED;
flags &= ~DB_READ_UNCOMMITTED; flags &= ~DB_READ_UNCOMMITTED;
} }
txn_flags |= child_isolation_flags;
if (flags&DB_TXN_NOWAIT) { if (flags&DB_TXN_NOWAIT) {
txn_flags |= DB_TXN_NOWAIT; txn_flags |= DB_TXN_NOWAIT;
flags &= ~DB_TXN_NOWAIT; flags &= ~DB_TXN_NOWAIT;
...@@ -1719,11 +1732,8 @@ static int toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t f ...@@ -1719,11 +1732,8 @@ static int toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t f
flags &= ~DB_TXN_NOSYNC; flags &= ~DB_TXN_NOSYNC;
} }
if (flags!=0) return toku_ydb_do_error(env, EINVAL, "Invalid flags passed to DB_ENV->txn_begin\n"); if (flags!=0) return toku_ydb_do_error(env, EINVAL, "Invalid flags passed to DB_ENV->txn_begin\n");
if (stxn) {
//Require child to have same isolation level as parent. //Require child to have same isolation level as parent.
uint32_t parent_isolation_flags = db_txn_struct_i(stxn)->flags & (DB_READ_UNCOMMITTED); //TODO: #2126 DB_READ_COMMITTED should be added here once supported. if (stxn && !inherit && parent_isolation_flags != child_isolation_flags) {
uint32_t child_isolation_flags = txn_flags & (DB_READ_UNCOMMITTED); //TODO: #2126 DB_READ_COMMITTED should be added here once supported.
if (parent_isolation_flags != child_isolation_flags)
return toku_ydb_do_error(env, EINVAL, "DB_ENV->txn_begin: Child transaction isolation level must match parent's isolation level.\n"); return toku_ydb_do_error(env, EINVAL, "DB_ENV->txn_begin: Child transaction isolation level must match parent's isolation level.\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment