2847
2831
csize numIncrementalIndices = theIncrementalIndices.size();
2849
STORE_TRACE1("Refreshing indexes for collection "
2851
theCollection->getName()->getStringValue().c_str() :
2854
for (csize idx = 0; idx < numIncrementalIndices; ++idx)
2856
ValueIndex* index = static_cast<ValueIndex*>(theIncrementalIndices[idx]);
2858
STORE_TRACE2("Index size before do = "
2859
<< (!index->isTreeIndex() ? index->size() : 0));
2861
store::IndexDelta& beforeDelta = theBeforeIndexDeltas[idx];
2862
store::IndexDelta& afterDelta = theAfterIndexDeltas[idx];
2863
store::IndexDelta& deletedDelta = theDeletedDocsIndexDeltas[idx];
2864
store::IndexDelta& insertedDelta = theInsertedDocsIndexDeltas[idx];
2866
csize& numBeforeApplied = theNumBeforeIndexDeltasApplied[idx];
2867
csize& numAfterApplied = theNumAfterIndexDeltasApplied[idx];
2868
csize& numDeletedApplied = theNumDeletedDocsIndexDeltasApplied[idx];
2869
csize& numInsertedApplied = theNumInsertedDocsIndexDeltasApplied[idx];
2871
store::IndexKey* key;
2874
store::IndexDelta::iterator ite;
2875
store::IndexDelta::iterator end;
2877
ite = beforeDelta.begin();
2878
end = beforeDelta.end();
2879
for (; ite != end; ++ite, ++numBeforeApplied)
2881
index->remove((*ite).second, (*ite).first);
2884
ite = afterDelta.begin();
2885
end = afterDelta.end();
2886
for (; ite != end; ++ite, ++numAfterApplied)
2888
node = (*ite).first;
2889
key = (*ite).second;
2891
// If the index had its own key obj already, delete the key obj that was
2892
// allocated during the delta creation.
2893
if (index->insert((*ite).second, node))
2895
assert(key != (*ite).second);
2900
STORE_TRACE2("deleted-delta size = " << deletedDelta.size());
2902
ite = deletedDelta.begin();
2903
end = deletedDelta.end();
2904
for (; ite != end; ++ite, ++numDeletedApplied)
2906
index->remove((*ite).second, (*ite).first);
2909
STORE_TRACE2("inserted-delta size = " << insertedDelta.size());
2911
ite = insertedDelta.begin();
2912
end = insertedDelta.end();
2913
for (; ite != end; ++ite, ++numInsertedApplied)
2915
node = (*ite).first;
2916
key = (*ite).second;
2918
if (index->insert((*ite).second, node))
2920
assert(key != (*ite).second);
2925
STORE_TRACE2("Index size after do = "
2926
<< (!index->isTreeIndex() ? index->size() : 0));
2929
STORE_TRACE1("Refreshed indexes for collection "
2931
theCollection->getName()->getStringValue().c_str() :
2833
if (numIncrementalIndices > 0)
2835
assert(theCollection);
2837
STORE_TRACE1("Refreshing indexes for collection "
2838
<< theCollection->getName()->getStringValue().c_str());
2840
for (csize idx = 0; idx < numIncrementalIndices; ++idx)
2842
if (theIncrementalIndices[idx]->isGeneral())
2843
refreshGeneralIndex(idx);
2845
refreshValueIndex(idx);
2848
STORE_TRACE1("Refreshed indexes for collection "
2849
<< theCollection->getName()->getStringValue().c_str()
2856
/*******************************************************************************
2858
********************************************************************************/
2859
void CollectionPul::refreshValueIndex(csize idx)
2861
ValueIndex* index = static_cast<ValueIndex*>(theIncrementalIndices[idx]);
2863
STORE_TRACE2("Index size before do = " << index->size());
2865
store::IndexDelta::ValueDelta&
2866
beforeDelta = theBeforeIndexDeltas[idx].getValueDelta();
2867
store::IndexDelta::ValueDelta&
2868
afterDelta = theAfterIndexDeltas[idx].getValueDelta();
2869
store::IndexDelta::ValueDelta&
2870
deletedDelta = theDeletedDocsIndexDeltas[idx].getValueDelta();
2871
store::IndexDelta::ValueDelta&
2872
insertedDelta = theInsertedDocsIndexDeltas[idx].getValueDelta();
2874
csize& numBeforeApplied = theNumBeforeIndexDeltasApplied[idx];
2875
csize& numAfterApplied = theNumAfterIndexDeltasApplied[idx];
2876
csize& numDeletedApplied = theNumDeletedDocsIndexDeltasApplied[idx];
2877
csize& numInsertedApplied = theNumInsertedDocsIndexDeltasApplied[idx];
2879
store::IndexKey* key;
2882
IndexDeltaImpl::ValueIterator ite;
2883
IndexDeltaImpl::ValueIterator end;
2885
ite = beforeDelta.begin();
2886
end = beforeDelta.end();
2887
for (; ite != end; ++ite, ++numBeforeApplied)
2889
index->remove((*ite).second, (*ite).first, false);
2892
ite = afterDelta.begin();
2893
end = afterDelta.end();
2894
for (; ite != end; ++ite, ++numAfterApplied)
2896
node = (*ite).first;
2897
key = (*ite).second;
2899
// If the index had its own key obj already, delete the key obj that was
2900
// allocated during the delta creation.
2901
if (index->insert((*ite).second, node))
2903
assert(key != (*ite).second);
2908
STORE_TRACE2("deleted-delta size = " << deletedDelta.size());
2910
ite = deletedDelta.begin();
2911
end = deletedDelta.end();
2912
for (; ite != end; ++ite, ++numDeletedApplied)
2914
index->remove((*ite).second, (*ite).first, false);
2917
STORE_TRACE2("inserted-delta size = " << insertedDelta.size());
2919
ite = insertedDelta.begin();
2920
end = insertedDelta.end();
2921
for (; ite != end; ++ite, ++numInsertedApplied)
2923
node = (*ite).first;
2924
key = (*ite).second;
2926
if (index->insert((*ite).second, node))
2928
assert(key != (*ite).second);
2933
STORE_TRACE2("Index size after do = " << index->size());
2937
/*******************************************************************************
2939
********************************************************************************/
2940
void CollectionPul::refreshGeneralIndex(csize idx)
2942
GeneralIndex* index = static_cast<GeneralIndex*>(theIncrementalIndices[idx]);
2944
store::IndexDelta::GeneralDelta&
2945
beforeDelta = theBeforeIndexDeltas[idx].getGeneralDelta();
2946
store::IndexDelta::GeneralDelta&
2947
afterDelta = theAfterIndexDeltas[idx].getGeneralDelta();
2948
store::IndexDelta::GeneralDelta&
2949
deletedDelta = theDeletedDocsIndexDeltas[idx].getGeneralDelta();
2950
store::IndexDelta::GeneralDelta&
2951
insertedDelta = theInsertedDocsIndexDeltas[idx].getGeneralDelta();
2953
csize& numBeforeApplied = theNumBeforeIndexDeltasApplied[idx];
2954
csize& numAfterApplied = theNumAfterIndexDeltasApplied[idx];
2955
csize& numDeletedApplied = theNumDeletedDocsIndexDeltasApplied[idx];
2956
csize& numInsertedApplied = theNumInsertedDocsIndexDeltasApplied[idx];
2961
IndexDeltaImpl::GeneralIterator ite;
2962
IndexDeltaImpl::GeneralIterator end;
2963
std::vector<store::Item_t>::iterator keyIte;
2964
std::vector<store::Item_t>::iterator keyEnd;
2966
STORE_TRACE2("before-delta size = " << deletedDelta.size());
2968
ite = beforeDelta.begin();
2969
end = beforeDelta.end();
2973
store::Item* nodep = (*ite).first.getp();
2975
index->remove((*ite).second, (*ite).first);
2979
if (ite != end && (*ite).first.getp() == nodep)
2981
index->remove((*ite).second, (*ite).first);
2982
++numDeletedApplied;
2985
// Call removeMultiKey() after removing the 2nd key for the same node.
2986
// We do this to make undo easier.
2987
index->removeMultiKey();
2989
while (ite != end && (*ite).first.getp() == nodep)
2991
index->remove((*ite).second, (*ite).first);
2998
STORE_TRACE2("after-delta size = " << deletedDelta.size());
3000
ite = afterDelta.begin();
3001
end = afterDelta.end();
3005
node = (*ite).first;
3006
key = (*ite).second;
3007
store::Item* nodep = node.getp();
3009
index->insert(key, node);
3013
if (ite != end && (*ite).first.getp() == nodep)
3015
node = (*ite).first;
3016
key = (*ite).second;
3018
index->insert(key, node);
3022
index->addMultiKey();
3024
while (ite != end && (*ite).first.getp() == nodep)
3026
node = (*ite).first;
3027
key = (*ite).second;
3029
index->insert(key, node);
3036
STORE_TRACE2("deleted-delta size = " << deletedDelta.size());
3038
ite = deletedDelta.begin();
3039
end = deletedDelta.end();
3043
store::Item* nodep = (*ite).first.getp();
3045
index->remove((*ite).second, (*ite).first);
3046
++numDeletedApplied;
3049
if (ite != end && (*ite).first.getp() == nodep)
3051
index->remove((*ite).second, (*ite).first);
3052
++numDeletedApplied;
3055
// Call removeMultiKey() after removing the 2nd key for the same node.
3056
// We do this to make undo easier.
3057
index->removeMultiKey();
3059
while (ite != end && (*ite).first.getp() == nodep)
3061
index->remove((*ite).second, (*ite).first);
3062
++numDeletedApplied;
3068
STORE_TRACE2("inserted-delta size = " << insertedDelta.size());
3070
ite = insertedDelta.begin();
3071
end = insertedDelta.end();
3075
node = (*ite).first;
3076
key = (*ite).second;
3077
store::Item* nodep = node.getp();
3079
index->insert(key, node);
3080
++numInsertedApplied;
3083
if (ite != end && (*ite).first.getp() == nodep)
3085
node = (*ite).first;
3086
key = (*ite).second;
3088
index->insert(key, node);
3089
++numInsertedApplied;
3092
index->addMultiKey();
3094
while (ite != end && (*ite).first.getp() == nodep)
3096
node = (*ite).first;
3097
key = (*ite).second;
3099
index->insert(key, node);
3100
++numInsertedApplied;
2950
3121
for (csize idx = 0; idx < numIncrementalIndices; ++idx)
2952
ValueIndex* index = static_cast<ValueIndex*>(theIncrementalIndices[idx]);
2954
STORE_TRACE2("Index size before undo = "
2955
<< (!index->isTreeIndex() ? index->size() : 0));
2957
store::IndexDelta& beforeDelta = theBeforeIndexDeltas[idx];
2958
store::IndexDelta& afterDelta = theAfterIndexDeltas[idx];
2959
store::IndexDelta& insertedDelta = theInsertedDocsIndexDeltas[idx];
2960
store::IndexDelta& deletedDelta = theDeletedDocsIndexDeltas[idx];
2962
csize numBeforeApplied = theNumBeforeIndexDeltasApplied[idx];
2963
csize numAfterApplied = theNumAfterIndexDeltasApplied[idx];
2964
csize numDeletedApplied = theNumDeletedDocsIndexDeltasApplied[idx];
2965
csize numInsertedApplied = theNumInsertedDocsIndexDeltasApplied[idx];
2967
store::IndexDelta::reverse_iterator ite;
2968
store::IndexDelta::reverse_iterator end;
2970
ite = insertedDelta.rbegin() + (insertedDelta.size() - numInsertedApplied);
2971
end = insertedDelta.rend();
2972
for (; ite != end; ++ite)
2974
index->remove((*ite).second, (*ite).first);
2977
ite = deletedDelta.rbegin() + (deletedDelta.size() - numDeletedApplied);
2978
end = deletedDelta.rend();
2979
for (; ite != end; ++ite)
2981
store::IndexKey* key = (*ite).second;
2983
// If the index takes ownership of the key obj, set the key ptr to null
2984
// so that the key obj will not be deleted during cleanIndexDeltas().
2985
if (!index->insert(key, (*ite).first))
2987
assert(key == (*ite).second);
2988
(*ite).second = NULL;
2992
ite = afterDelta.rbegin() + (afterDelta.size() - numAfterApplied);
2993
end = afterDelta.rend();
2994
for (; ite != end; ++ite)
2996
index->remove((*ite).second, (*ite).first);
2999
ite = beforeDelta.rbegin() + (beforeDelta.size() - numBeforeApplied);
3000
end = beforeDelta.rend();
3001
for (; ite != end; ++ite)
3003
store::IndexKey* key = (*ite).second;
3005
// If the index takes ownership of the key obj, set the key ptr to null
3006
// so that the key obj will not be deleted during cleanIndexDeltas().
3007
if (!index->insert(key, (*ite).first))
3009
assert(key == (*ite).second);
3010
(*ite).second = NULL;
3014
STORE_TRACE2("Index size after undo = "
3015
<< (!index->isTreeIndex() ? index->size() : 0));
3123
if (theIncrementalIndices[idx]->isGeneral())
3124
undoGeneralIndexRefresh(idx);
3126
undoValueIndexRefresh(idx);
3018
3129
STORE_TRACE1("Reverted indexes for collection "
3026
3137
/*******************************************************************************
3139
********************************************************************************/
3140
void CollectionPul::undoValueIndexRefresh(csize idx)
3142
ValueIndex* index = static_cast<ValueIndex*>(theIncrementalIndices[idx]);
3144
STORE_TRACE2("Index size before undo = " << index->size());
3146
store::IndexDelta::ValueDelta&
3147
beforeDelta = theBeforeIndexDeltas[idx].getValueDelta();
3148
store::IndexDelta::ValueDelta&
3149
afterDelta = theAfterIndexDeltas[idx].getValueDelta();
3150
store::IndexDelta::ValueDelta&
3151
insertedDelta = theInsertedDocsIndexDeltas[idx].getValueDelta();
3152
store::IndexDelta::ValueDelta&
3153
deletedDelta = theDeletedDocsIndexDeltas[idx].getValueDelta();
3155
csize numBeforeApplied = theNumBeforeIndexDeltasApplied[idx];
3156
csize numAfterApplied = theNumAfterIndexDeltasApplied[idx];
3157
csize numDeletedApplied = theNumDeletedDocsIndexDeltasApplied[idx];
3158
csize numInsertedApplied = theNumInsertedDocsIndexDeltasApplied[idx];
3160
IndexDeltaImpl::ReverseValueIterator ite;
3161
IndexDeltaImpl::ReverseValueIterator end;
3163
ite = insertedDelta.rbegin() + (insertedDelta.size() - numInsertedApplied);
3164
end = insertedDelta.rend();
3165
for (; ite != end; ++ite)
3167
index->remove((*ite).second, (*ite).first, false);
3170
ite = deletedDelta.rbegin() + (deletedDelta.size() - numDeletedApplied);
3171
end = deletedDelta.rend();
3172
for (; ite != end; ++ite)
3174
store::IndexKey* key = (*ite).second;
3176
// If the index takes ownership of the key obj, set the key ptr to null
3177
// so that the key obj will not be deleted during cleanIndexDeltas().
3178
if (!index->insert(key, (*ite).first))
3180
assert(key == (*ite).second);
3181
(*ite).second = NULL;
3185
ite = afterDelta.rbegin() + (afterDelta.size() - numAfterApplied);
3186
end = afterDelta.rend();
3187
for (; ite != end; ++ite)
3189
index->remove((*ite).second, (*ite).first, false);
3192
ite = beforeDelta.rbegin() + (beforeDelta.size() - numBeforeApplied);
3193
end = beforeDelta.rend();
3194
for (; ite != end; ++ite)
3196
store::IndexKey* key = (*ite).second;
3198
// If the index takes ownership of the key obj, set the key ptr to null
3199
// so that the key obj will not be deleted during cleanIndexDeltas().
3200
if (!index->insert(key, (*ite).first))
3202
assert(key == (*ite).second);
3203
(*ite).second = NULL;
3207
STORE_TRACE2("Index size after undo = " << index->size());
3211
/*******************************************************************************
3213
********************************************************************************/
3214
void CollectionPul::undoGeneralIndexRefresh(csize idx)
3216
GeneralIndex* index = static_cast<GeneralIndex*>(theIncrementalIndices[idx]);
3218
store::IndexDelta::GeneralDelta&
3219
beforeDelta = theBeforeIndexDeltas[idx].getGeneralDelta();
3220
store::IndexDelta::GeneralDelta&
3221
afterDelta = theAfterIndexDeltas[idx].getGeneralDelta();
3222
store::IndexDelta::GeneralDelta&
3223
insertedDelta = theInsertedDocsIndexDeltas[idx].getGeneralDelta();
3224
store::IndexDelta::GeneralDelta&
3225
deletedDelta = theDeletedDocsIndexDeltas[idx].getGeneralDelta();
3227
csize numBeforeApplied = theNumBeforeIndexDeltasApplied[idx];
3228
csize numAfterApplied = theNumAfterIndexDeltasApplied[idx];
3229
csize numDeletedApplied = theNumDeletedDocsIndexDeltasApplied[idx];
3230
csize numInsertedApplied = theNumInsertedDocsIndexDeltasApplied[idx];
3232
IndexDeltaImpl::ReverseGeneralIterator ite;
3233
IndexDeltaImpl::ReverseGeneralIterator end;
3234
std::vector<store::Item_t>::reverse_iterator keyIte;
3235
std::vector<store::Item_t>::reverse_iterator keyEnd;
3239
ite = insertedDelta.rbegin() + (insertedDelta.size() - numInsertedApplied);
3240
end = insertedDelta.rend();
3244
store::Item* nodep = (*ite).first.getp();
3246
index->remove((*ite).second, (*ite).first);
3249
if (ite != end && (*ite).first.getp() == nodep)
3251
index->removeMultiKey();
3255
index->remove((*ite).second, (*ite).first);
3258
while (ite != end && (*ite).first.getp() == nodep);
3264
ite = deletedDelta.rbegin() + (deletedDelta.size() - numDeletedApplied);
3265
end = deletedDelta.rend();
3269
store::Item* nodep = (*ite).first.getp();
3271
index->insert((*ite).second, (*ite).first);
3274
if (ite != end && (*ite).first.getp() == nodep)
3276
index->addMultiKey();
3280
index->insert((*ite).second, (*ite).first);
3283
while (ite != end && (*ite).first.getp() == nodep);
3289
ite = afterDelta.rbegin() + (afterDelta.size() - numAfterApplied);
3290
end = afterDelta.rend();
3294
store::Item* nodep = (*ite).first.getp();
3296
index->remove((*ite).second, (*ite).first);
3299
if (ite != end && (*ite).first.getp() == nodep)
3301
index->removeMultiKey();
3305
index->remove((*ite).second, (*ite).first);
3308
while (ite != end && (*ite).first.getp() == nodep);
3314
ite = beforeDelta.rbegin() + (beforeDelta.size() - numBeforeApplied);
3315
end = beforeDelta.rend();
3319
store::Item* nodep = (*ite).first.getp();
3321
index->insert((*ite).second, (*ite).first);
3324
if (ite != end && (*ite).first.getp() == nodep)
3326
index->addMultiKey();
3330
index->insert((*ite).second, (*ite).first);
3333
while (ite != end && (*ite).first.getp() == nodep);
3339
/*******************************************************************************
3027
3340
The method is called from CollectionPul::finalizeUpdates()
3028
3341
********************************************************************************/
3029
3342
void CollectionPul::truncateIndexes()