Commit e70d1493 authored by unknown's avatar unknown

ndb - super pool update (future use)


storage/ndb/src/kernel/vm/SuperPool.cpp:
  super pool update
storage/ndb/src/kernel/vm/SuperPool.hpp:
  super pool update
storage/ndb/src/kernel/vm/testSuperPool.cpp:
  super pool update
parent 835426ce
This diff is collapsed.
This diff is collapsed.
...@@ -81,19 +81,22 @@ cmpPtrP(const void* a, const void* b) ...@@ -81,19 +81,22 @@ cmpPtrP(const void* a, const void* b)
static Uint32 loopcount = 3; static Uint32 loopcount = 3;
template <Uint32 sz> template <class T>
void static void
sp_test(SuperPool& sp) sp_test(GroupPool& gp)
{ {
typedef A<sz> T; SuperPool& sp = gp.m_superPool;
RecordPool<T> rp(sp); RecordPool<T> rp(gp);
assert(gp.m_totPages == gp.m_freeList.m_pageCount);
SuperPool::RecInfo& ri = rp.m_recInfo; SuperPool::RecInfo& ri = rp.m_recInfo;
Uint32 pageCount = sp.m_totalSize / sp.m_pageSize; Uint32 pageCount = sp.m_totPages;
Uint32 perPage = rp.m_recInfo.m_maxUseCount; Uint32 perPage = rp.m_recInfo.m_maxPerPage;
Uint32 perPool = perPage * pageCount; Uint32 perPool = perPage * pageCount;
ndbout << "pages=" << pageCount << " perpage=" << perPage << " perpool=" << perPool << endl; ndbout << "pages=" << pageCount << " perpage=" << perPage << " perpool=" << perPool << endl;
Ptr<T>* ptrList = new Ptr<T> [perPool]; Ptr<T>* ptrList = new Ptr<T> [perPool];
memset(ptrList, 0x1f, perPool * sizeof(Ptr<T>)); memset(ptrList, 0x1f, perPool * sizeof(Ptr<T>));
Uint32 verify = 1000;
Uint32 useCount;
Uint32 loop; Uint32 loop;
for (loop = 0; loop < loopcount; loop++) { for (loop = 0; loop < loopcount; loop++) {
ndbout << "loop " << loop << endl; ndbout << "loop " << loop << endl;
...@@ -101,25 +104,26 @@ sp_test(SuperPool& sp) ...@@ -101,25 +104,26 @@ sp_test(SuperPool& sp)
// seize all // seize all
ndbout << "seize all" << endl; ndbout << "seize all" << endl;
for (i = 0; i < perPool + 1; i++) { for (i = 0; i < perPool + 1; i++) {
if (verify == 0 || urandom(perPool) < verify)
sp.verify(ri);
j = i; j = i;
sp.verify(ri);
Ptr<T> ptr1 = { 0, RNIL }; Ptr<T> ptr1 = { 0, RNIL };
if (! rp.seize(ptr1)) if (! rp.seize(ptr1))
break; break;
// write value
ptr1.p->fill(); ptr1.p->fill();
ptr1.p->check(); ptr1.p->check();
// verify getPtr
Ptr<T> ptr2 = { 0, ptr1.i }; Ptr<T> ptr2 = { 0, ptr1.i };
rp.getPtr(ptr2); rp.getPtr(ptr2);
assert(ptr1.i == ptr2.i && ptr1.p == ptr2.p); assert(ptr1.i == ptr2.i && ptr1.p == ptr2.p);
// save
ptrList[j] = ptr1; ptrList[j] = ptr1;
} }
assert(i == perPool);
assert(ri.m_totalUseCount == perPool && ri.m_totalRecCount == perPool);
sp.verify(ri); sp.verify(ri);
ndbout << "seized " << i << endl;
assert(i == perPool);
useCount = sp.getRecUseCount(ri);
assert(useCount == perPool);
// check duplicates // check duplicates
ndbout << "check dups" << endl;
{ {
Ptr<T>* ptrList2 = new Ptr<T> [perPool]; Ptr<T>* ptrList2 = new Ptr<T> [perPool];
memcpy(ptrList2, ptrList, perPool * sizeof(Ptr<T>)); memcpy(ptrList2, ptrList, perPool * sizeof(Ptr<T>));
...@@ -135,7 +139,8 @@ sp_test(SuperPool& sp) ...@@ -135,7 +139,8 @@ sp_test(SuperPool& sp)
ndbout << "release all" << endl; ndbout << "release all" << endl;
Uint32 coprime = random_coprime(perPool); Uint32 coprime = random_coprime(perPool);
for (i = 0; i < perPool; i++) { for (i = 0; i < perPool; i++) {
sp.verify(ri); if (verify == 0 || urandom(perPool) < verify)
sp.verify(ri);
switch (loop % 3) { switch (loop % 3) {
case 0: // ascending case 0: // ascending
j = i; j = i;
...@@ -153,27 +158,31 @@ sp_test(SuperPool& sp) ...@@ -153,27 +158,31 @@ sp_test(SuperPool& sp)
rp.release(ptr); rp.release(ptr);
assert(ptr.i == RNIL && ptr.p == 0); assert(ptr.i == RNIL && ptr.p == 0);
} }
sp.setCurrPage(ri, RNIL);
assert(ri.m_totalUseCount == 0 && ri.m_totalRecCount == 0);
sp.verify(ri); sp.verify(ri);
useCount = sp.getRecUseCount(ri);
assert(useCount == 0);
// seize/release at random // seize/release at random
ndbout << "seize/release at random" << endl; ndbout << "seize/release at random" << endl;
for (i = 0; i < loopcount * perPool; i++) { for (i = 0; i < loopcount * perPool; i++) {
if (verify == 0 || urandom(perPool) < verify)
sp.verify(ri);
j = urandom(perPool); j = urandom(perPool);
Ptr<T>& ptr = ptrList[j]; Ptr<T>& ptr = ptrList[j];
if (ptr.i == RNIL) { if (ptr.i == RNIL) {
rp.seize(ptr); if (rp.seize(ptr))
ptr.p->fill(); ptr.p->fill();
} else { } else {
ptr.p->check(); ptr.p->check();
rp.release(ptr); rp.release(ptr);
} }
} }
ndbout << "used " << ri.m_totalUseCount << endl; ndbout << "used " << ri.m_useCount << endl;
sp.verify(ri); sp.verify(ri);
// release all // release all
ndbout << "release all" << endl; ndbout << "release all" << endl;
for (i = 0; i < perPool; i++) { for (i = 0; i < perPool; i++) {
if (verify == 0 || urandom(perPool) < verify)
sp.verify(ri);
j = i; j = i;
Ptr<T>& ptr = ptrList[j]; Ptr<T>& ptr = ptrList[j];
if (ptr.i != RNIL) { if (ptr.i != RNIL) {
...@@ -181,40 +190,54 @@ sp_test(SuperPool& sp) ...@@ -181,40 +190,54 @@ sp_test(SuperPool& sp)
rp.release(ptr); rp.release(ptr);
} }
} }
sp.setCurrPage(ri, RNIL);
assert(ri.m_totalUseCount == 0 && ri.m_totalRecCount == 0);
sp.verify(ri); sp.verify(ri);
useCount = sp.getRecUseCount(ri);
assert(useCount == 0);
} }
// done // done
delete [] ptrList; delete [] ptrList;
} }
static Uint32 pageCount = 99;
static Uint32 pageSize = 32768; static Uint32 pageSize = 32768;
static Uint32 pageBits = 15; static Uint32 pageBits = 17;
const Uint32 sz1 = 3, sz2 = 4, sz3 = 53, sz4 = 424, sz5 = 5353; const Uint32 sz1 = 3;
const Uint32 sz2 = 4;
template void sp_test<sz1>(SuperPool& sp); const Uint32 sz3 = 53;
template void sp_test<sz2>(SuperPool& sp); const Uint32 sz4 = 424;
template void sp_test<sz3>(SuperPool& sp); const Uint32 sz5 = 5353;
template void sp_test<sz4>(SuperPool& sp);
template void sp_test<sz5>(SuperPool& sp); typedef A<sz1> T1;
typedef A<sz2> T2;
typedef A<sz3> T3;
typedef A<sz4> T4;
typedef A<sz5> T5;
template static void sp_test<T1>(GroupPool& sp);
template static void sp_test<T2>(GroupPool& sp);
template static void sp_test<T3>(GroupPool& sp);
template static void sp_test<T4>(GroupPool& sp);
template static void sp_test<T5>(GroupPool& sp);
int int
main() main()
{ {
HeapPool sp(pageSize, pageBits); HeapPool sp(pageSize, pageBits);
sp.setSizes(pageCount * pageSize); sp.setInitPages(7);
if (! sp.init()) sp.setMaxPages(7);
if (! sp.allocMemory())
assert(false); assert(false);
GroupPool gp(sp);
Uint16 s = (Uint16)getpid(); Uint16 s = (Uint16)getpid();
srandom(s); srandom(s);
ndbout << "rand " << s << endl; ndbout << "rand " << s << endl;
sp_test<sz1>(sp); int count = 0;
sp_test<sz2>(sp); while (++count <= 1) {
sp_test<sz3>(sp); sp_test<T1>(gp);
sp_test<sz4>(sp); sp_test<T2>(gp);
sp_test<sz5>(sp); sp_test<T3>(gp);
sp_test<T4>(gp);
sp_test<T5>(gp);
}
return 0; return 0;
} }
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