Changeset: 30602e169e8f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=30602e169e8f
Added Files:
        monetdb5/extras/crackers/crackers_selectholpl_ops.mx
Modified Files:
        monetdb5/extras/crackers/Makefile.ag
        monetdb5/extras/crackers/crackers.mx
        monetdb5/extras/crackers/crackers_AVL_tree.mx
        monetdb5/extras/crackers/crackers_holistic.c
        monetdb5/extras/crackers/crackers_holistic.h
        monetdb5/extras/crackers/crackers_index.mx
        monetdb5/extras/crackers/crackers_selecthol_ops.mx
Branch: holindex
Log Message:

Make holistic indexing thread-safe using either column-latches or piece-latches.


diffs (truncated from 1636 to 300 lines):

diff --git a/monetdb5/extras/crackers/Makefile.ag 
b/monetdb5/extras/crackers/Makefile.ag
--- a/monetdb5/extras/crackers/Makefile.ag
+++ b/monetdb5/extras/crackers/Makefile.ag
@@ -44,6 +44,7 @@ lib_crackers = {
                          crackers_selectst_ops.mx \
                          crackers_selecthol_ops.mx \
                          crackers_selectholst_ops.mx \
+                         crackers_selectholpl_ops.mx \
                          crackers_updates.mx \
                          crackers_sideways.mx \
                          crackers_sidewayshol.mx \
diff --git a/monetdb5/extras/crackers/crackers.mx 
b/monetdb5/extras/crackers/crackers.mx
--- a/monetdb5/extras/crackers/crackers.mx
+++ b/monetdb5/extras/crackers/crackers.mx
@@ -341,6 +341,45 @@ address CRKthetaselectholst_@2
 comment "Retrieve the subset using a cracker
         index producing preferably a BATview.";
 
+command selectholpl(b:bat[:oid,:@2],l:@2,h:@2):bat[:oid,:@2]
+address CRKselectholpl_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+command selectholpl(b:bat[:oid,:@2],l:@2):bat[:oid,:@2]
+address CRKselectholplValue_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+command selectholpl(b:bat[:oid,:@2],l:@2,h:@2,li:bit,hi:bit):bat[:oid,:@2]
+address CRKselectholplBounds_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+command uselectholpl(b:bat[:any_1,:@2],l:@2,h:@2):bat[:any_1,:void]
+address CRKuselectholpl_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+command uselectholpl(b:bat[:any_1,:@2],l:@2):bat[:any_1,:void]
+address CRKuselectholplValue_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+command 
uselectholpl(b:bat[:any_1,:@2],l:@2,h:@2,li:bit,hi:bit):bat[:any_1,:void]
+address CRKuselectholplBounds_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+command thetauselectholpl(b:bat[:any_1,:@2],v:@2,op:str):bat[:any_1,:void]
+address CRKthetauselectholpl_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
+
+command thetaselectholpl(b:bat[:any_1,:@2],v:@2,op:str):bat[:any_1,:@2]
+address CRKthetaselectholpl_@2
+comment "Retrieve the subset using a cracker
+        index producing preferably a BATview.";
 
 @
 @= JoinSelect
@@ -806,6 +845,7 @@ comment "make new map for debugging";
 #include "crackers_selectst_ops.h"
 #include "crackers_selecthol_ops.h"
 #include "crackers_selectholst_ops.h"
+#include "crackers_selectholpl_ops.h"
 #include "crackers_holistic.h"
 #include "crackers_holisticsideways.h"
 #include "crackers_core_unordered.h"
@@ -843,6 +883,7 @@ struct storageManagement *StorageInfo = 
 
 int IndexEntries = 20000000; /* Initial size used for the bat that stores 
index values */
 
+
 /* Temp variables used to test the effect of stop updating the index, they 
operate only on one cracker bat */
 int IndexSize = 0;
 int IndexStop = 10000000;
diff --git a/monetdb5/extras/crackers/crackers_AVL_tree.mx 
b/monetdb5/extras/crackers/crackers_AVL_tree.mx
--- a/monetdb5/extras/crackers/crackers_AVL_tree.mx
+++ b/monetdb5/extras/crackers/crackers_AVL_tree.mx
@@ -660,6 +660,7 @@ InsertTree_@1(int m, oid indexPosition, 
                current->isPreviousSmaller = FALSE;
                current->hols = (oid)0;
                current->slice = -1;
+               pthread_rwlock_init(&current->pieceLock,0);
                *newNode = current;
                goto end;
         }
diff --git a/monetdb5/extras/crackers/crackers_holistic.c 
b/monetdb5/extras/crackers/crackers_holistic.c
--- a/monetdb5/extras/crackers/crackers_holistic.c
+++ b/monetdb5/extras/crackers/crackers_holistic.c
@@ -28,6 +28,8 @@ static FrequencyNode *_InternalFrequency
 static FrequencyNode *_InternalFrequencyStructB = NULL;
 static MT_Lock frequencylock;
 static MT_Id idletime_thread;
+MT_Lock CRKIndexLock;
+
 
 int isIdleQuery = 0;
 IdleFuncPtr IdleFunc;
@@ -37,6 +39,7 @@ CRKinitHolistic(int *ret)
 {
        IdleFunc=&CRKrandomCrack;
        MT_lock_init(&frequencylock, "FrequencyStruct");
+       MT_lock_init(&CRKIndexLock, "Cracker Index Lock");
        MT_create_thread(&idletime_thread,(void (*)(void *))HeartbeatCPUload, 
IdleFunc, MT_THR_JOINABLE);
        *ret = 0;
        return MAL_SUCCEED;
@@ -48,7 +51,6 @@ getFrequencyStruct(char which)
 {
        FrequencyNode **theNode = NULL;
 
-       MT_lock_set(&frequencylock, "getFrequencyStruct");
        switch (which) {
                 case 'A':
                         theNode = &_InternalFrequencyStructA;
@@ -63,7 +65,6 @@ getFrequencyStruct(char which)
         /* GDKzalloc = calloc = malloc + memset(0) */
         if (*theNode == NULL)
                 *theNode = GDKzalloc(sizeof(FrequencyNode));
-       MT_lock_unset(&frequencylock, "getFrequencyStruct");
        
        return *theNode;
 }
@@ -71,29 +72,52 @@ getFrequencyStruct(char which)
 void 
 push(int bat_id,FrequencyNode* head)
 {
-       FrequencyNode* new_node;
-       new_node=(FrequencyNode *) GDKmalloc(sizeof(FrequencyNode));
-       new_node->bid=bat_id;
-       new_node->c=1;
-       new_node->f1=0;
-       new_node->f2=0;
-       new_node->weight=0.0; /*weight=f1*((N/c)-L1)*/
-       new_node->next=head->next;
-       head->next=new_node; 
+       FrequencyNode* new_node,*temp;
+       MT_lock_set(&frequencylock, "getFrequencyStruct");
+       temp=head;
+       while((temp->bid != bat_id))
+       {
+               temp=temp->next;
+               if (temp==NULL)
+               {
+                       new_node=(FrequencyNode *) 
GDKmalloc(sizeof(FrequencyNode));
+                       new_node->bid=bat_id;
+                       new_node->c=1;
+                       new_node->f1=0;
+                       new_node->f2=0;
+                       new_node->weight=0.0; /*weight=f1*((N/c)-L1)*/
+                       MT_lock_init(&new_node->nodeLock, "Lock Node");
+                       new_node->next=head->next;
+                       head->next=new_node;
+                       break;
+               }
+       } 
+       MT_lock_unset(&frequencylock, "getFrequencyStruct");
 }
 /*this function pushes nodes in the list and is used in cost models: 1,3,5*/
 void 
 push_2(int bat_id,FrequencyNode* head,int N,int L1)
 {
-       FrequencyNode* new_node;
-       new_node=(FrequencyNode *) GDKmalloc(sizeof(FrequencyNode));
-       new_node->bid=bat_id;
-       new_node->c=1;
-       new_node->f1=0;
-       new_node->f2=0;
-       new_node->weight=N-L1;
-       new_node->next=head->next;
-       head->next=new_node; 
+       FrequencyNode* new_node,*temp;
+       MT_lock_set(&frequencylock, "getFrequencyStruct");
+       temp=head;
+       while((temp->bid != bat_id))
+       {
+               temp=temp->next;
+               if (temp==NULL)
+               {
+                       new_node=(FrequencyNode *) 
GDKmalloc(sizeof(FrequencyNode));
+                       new_node->bid=bat_id;
+                       new_node->c=1;
+                       new_node->f1=0;
+                       new_node->f2=0;
+                       new_node->weight=N-L1;
+                       new_node->next=head->next;
+                       head->next=new_node;
+                       break;
+               }
+       }
+       MT_lock_unset(&frequencylock, "getFrequencyStruct");     
 }
 
 FrequencyNode*
@@ -227,9 +251,11 @@ pickRandom(FrequencyNode* head)
 double
 changeWeight_1(FrequencyNode* node,int N,int L1)
 {
+
        int p; /*number of pieces in the index*/
        double Sp; /*average size of each piece*/
        double d; /*distance from optimal piece(L1)*/
+       MT_lock_set(&node->nodeLock, "Lock Node");
        p = node->c;
        Sp =((double)N)/p;      
        d = Sp - L1;
@@ -243,6 +269,7 @@ changeWeight_1(FrequencyNode* node,int N
        }
 
        fprintf(stderr,"bid=%d f1=%d f2=%d p=%d Sp=%lf d=%lf 
W=%lf\n",node->bid,node->f1,node->f2,p,Sp,d,node->weight);
+       MT_lock_unset(&node->nodeLock, "Lock Node");
        return node->weight;
 }
 
diff --git a/monetdb5/extras/crackers/crackers_holistic.h 
b/monetdb5/extras/crackers/crackers_holistic.h
--- a/monetdb5/extras/crackers/crackers_holistic.h
+++ b/monetdb5/extras/crackers/crackers_holistic.h
@@ -30,12 +30,14 @@ typedef struct frequency{
        int             f1;             /*number of queries that triggered 
cracking*/
        int             f2;             /*number of queries that did not 
trigger cracking(because the value already existed in the index)*/
        double          weight;
+       MT_Lock         nodeLock;
        struct frequency *next;
 
 }FrequencyNode;
 
 typedef  str (*IdleFuncPtr)(int *);
 crackers_export int isIdleQuery;
+crackers_export MT_Lock CRKIndexLock;
 
 crackers_export FrequencyNode *getFrequencyStruct(char which);
 crackers_export void push(int bat_id,FrequencyNode* head);
diff --git a/monetdb5/extras/crackers/crackers_index.mx 
b/monetdb5/extras/crackers/crackers_index.mx
--- a/monetdb5/extras/crackers/crackers_index.mx
+++ b/monetdb5/extras/crackers/crackers_index.mx
@@ -145,6 +145,8 @@ struct Node{
        /*for merging techniques*/
        oid sliceSize;          
        oid contiguousArea;
+
+       pthread_rwlock_t pieceLock;     
 };
 
 typedef struct {
@@ -195,6 +197,9 @@ typedef struct {
        /* for sort merge techniques */
        struct sortMergeNode *smNode;
 
+       MT_Lock columnLock;
+       pthread_rwlock_t columnRWLock;
+
 } CrackerIndexNode;
 
 /* for storage management */
@@ -510,8 +515,10 @@ addCrackerIndex_@1(int m, @1 *value, bit
 
                 CrackerIndex[m].Tree->nextValue = NULL;        
                CrackerIndex[m].Tree->indexPosition = index; 
-                       
+               pthread_rwlock_init(&CrackerIndex[m].Tree->pieceLock,0);
                CrackerIndex[m].pieces++;
+               MT_lock_init(&CrackerIndex[m].columnLock,0);
+               pthread_rwlock_init(&CrackerIndex[m].columnRWLock, 0);
                 return CrackerIndex[m].Tree;
         }
 
diff --git a/monetdb5/extras/crackers/crackers_selecthol_ops.mx 
b/monetdb5/extras/crackers/crackers_selecthol_ops.mx
--- a/monetdb5/extras/crackers/crackers_selecthol_ops.mx
+++ b/monetdb5/extras/crackers/crackers_selecthol_ops.mx
@@ -74,9 +74,6 @@ crackers_export str CRKthetauselecthol_@
 #include "monetdb_config.h"
 #include "crackers.h"
 
-static MT_Lock rangeselectlock;
-
-
 /* Local support functions and macros */
 @:TypeSwitch(crackOperations)@
 
@@ -266,7 +263,12 @@ createView:
 
        BBPunfix(b->batCacheid);
        BBPunfix(c->batCacheid);
-       MT_lock_unset(&rangeselectlock, "RangeSelectBody");
+       if (createIndex==1)
+       {
+               MT_lock_unset(&CRKIndexLock,"Cracker Index Lock");
+               createIndex=0;  
+       }
+       MT_lock_unset(&CrackerIndex[m].columnLock,"Lock Attribute");
 
 @
 @= RangeSelectBody
@@ -275,6 +277,7 @@ createView:
        BAT *view;
        int  m;
        int *t;
+       int createIndex=0;
        oid vl=0, vh=0, posl, posh;
        /* vl and vh are the low and high index values to create the view with 
the result */
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to