3323 Jonas Oreland 2010-10-27
ndb - bug#57761 - fix strict alias violation in DataBuffer::seize()
modified:
storage/ndb/src/kernel/vm/DataBuffer.hpp
3322 Jonas Oreland 2010-10-25
ndb - bug#57522 - post autotest fix 1. Fix upgrade which was made "upside-down"
modified:
storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp
=== modified file 'storage/ndb/src/kernel/vm/DataBuffer.hpp'
--- a/storage/ndb/src/kernel/vm/DataBuffer.hpp 2009-10-07 14:08:22 +0000
+++ b/storage/ndb/src/kernel/vm/DataBuffer.hpp 2010-10-27 06:35:00 +0000
@@ -263,10 +263,14 @@ DataBuffer<sz>::append(const Uint32* src
return false;
}
DataBufferIterator it;
-
- if(position(it, pos) && import(it, src, len)){
+
+ bool b0 = true, b1 = true;
+ if ((b0 = position(it, pos)) && (b1 = import(it, src, len)))
+ {
return true;
}
+
+ ndbout_c("%u %u", b0, b1);
abort();
return false;
}
@@ -311,57 +315,60 @@ DataBuffer<sz>::DataBuffer(DataBufferPoo
template<Uint32 sz>
inline
bool
-DataBuffer<sz>::seize(Uint32 n){
- Uint32 rest; // Free space in last segment (currently)
- Segment* prevPtr;
-
- if(head.firstItem == RNIL){
- rest = 0;
- prevPtr = (Segment*)&head.firstItem;
- } else {
- rest = (sz - (head.used % sz)) % sz;
- prevPtr = thePool.getPtr(head.lastItem);
+DataBuffer<sz>::seize(Uint32 n)
+{
+ Uint32 req = n;
+ Uint32 used = head.used;
+ Uint32 last = used % sz; // (almost) used in last segment
+ Uint32 rest = last ? sz - last : 0; // Free in last segment
+
+ if (rest >= n)
+ {
+ /**
+ * No extra allocation needed
+ */
+ head.used = used + n;
+ return true;
}
-
+
+ n -= rest;
+
/**
* Check for space
*/
- Uint32 free = thePool.getNoOfFree() * sz + rest;
- if(n > free){
+ Uint32 free = thePool.getNoOfFree() * sz;
+ if (n > free)
+ {
return false;
}
-
- Uint32 used = head.used + n;
- Ptr<Segment> currPtr;
- currPtr.i = head.lastItem;
- while(n >= sz){
- if(0)
- ndbout_c("n(%d) %c sz(%d)", n, (n>sz?'>':(n<sz?'<':'=')), sz);
-
- thePool.seize(currPtr); assert(currPtr.i != RNIL);
- prevPtr->nextPool = currPtr.i;
-
- prevPtr = currPtr.p;
- prevPtr->nextPool = RNIL;
+ Ptr<Segment> firstPtr;
+ thePool.seize(firstPtr);
+ Ptr<Segment> lastPtr = firstPtr;
+
+ while (n > sz)
+ {
+ Ptr<Segment> tmp;
+ thePool.seize(tmp);
+ lastPtr.p->nextPool = tmp.i;
+ lastPtr = tmp;
n -= sz;
}
+ lastPtr.p->nextPool = RNIL;
- if(0){
- Uint32 pos = rest + n;
- ndbout_c("rest(%d), n(%d) pos=%d %c sz(%d)",
- rest, n, pos, (pos>sz?'>':(pos<sz?'<':'=')), sz);
+ head.used = used + req;
+ if (head.firstItem == RNIL)
+ {
+ head.firstItem = firstPtr.i;
+ assert(head.lastItem == RNIL);
}
-
- if(n > rest){
- thePool.seize(currPtr);
- assert(currPtr.i != RNIL);
- prevPtr->nextPool = currPtr.i;
- currPtr.p->nextPool = RNIL;
+ else
+ {
+ Segment* tail = thePool.getPtr(head.lastItem);
+ assert(tail->nextPool == RNIL);
+ tail->nextPool = firstPtr.i;
}
-
- head.used = used;
- head.lastItem = currPtr.i;
+ head.lastItem = lastPtr.i;
#if 0
{
Attachment: [text/bzr-bundle] bzr/jonas@mysql.com-20101027063500-2vte8pekf0i8f1oe.bundle
| Thread |
|---|
| • bzr push into mysql-5.1-telco-6.3 branch (jonas:3322 to 3323) Bug#57761 | Jonas Oreland | 27 Oct |