00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "fennel/common/CommonPreamble.h"
00023 #include "fennel/lucidera/colstore/LcsClusterDump.h"
00024 #include "fennel/lucidera/colstore/LcsBitOps.h"
00025 #include "fennel/tuple/TupleData.h"
00026 #include "fennel/tuple/UnalignedAttributeAccessor.h"
00027 #include "fennel/common/TraceSource.h"
00028 #include <stdarg.h>
00029
00030 using namespace std;
00031
00032 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/lucidera/colstore/LcsClusterDump.cpp#15 $");
00033
00034 const uint lnLen = 80;
00035 const uint lnSep = 1;
00036 const uint lnValIdx = 6;
00037 const uint lnColLen = 6;
00038 const uint lnByte = 3;
00039
00040 const uint lnChar = 1;
00041
00042
00043 const uint nByte = (lnLen - lnValIdx - lnColLen - lnSep) / (lnByte + lnChar);
00044
00045
00046 const uint oByte = lnValIdx + lnColLen;
00047
00048
00049 const uint oStr = oByte + nByte * lnByte + lnSep;
00050
00051
00052 const uint MaxReadBatch = 64;
00053
00054 LcsClusterDump::LcsClusterDump(
00055 BTreeDescriptor const &bTreeDescriptor,
00056 TupleDescriptor const &colTupleDescInit,
00057 TraceLevel traceLevelInit,
00058 SharedTraceTarget pTraceTargetInit,
00059 std::string nameInit) :
00060 LcsClusterAccessBase(bTreeDescriptor),
00061 TraceSource(pTraceTargetInit, nameInit)
00062 {
00063 colTupleDesc = colTupleDescInit;
00064 traceLevel = traceLevelInit;
00065 }
00066
00067
00068 void LcsClusterDump::dump(
00069 uint64_t pageId, PConstLcsClusterNode pHdr, uint szBlock)
00070 {
00071 PBuffer pBlock = (PBuffer) pHdr;
00072 uint i, j, k;
00073 uint16_t *pO;
00074 PBuffer pR;
00075
00076 uint count;
00077
00078 uint nBits;
00079 PLcsBatchDir pBatch;
00080 WidthVec w;
00081 PtrVec p;
00082 uint iV;
00083 uint8_t *pBit;
00084 uint16_t v[MaxReadBatch];
00085 const char *mode;
00086
00087
00088
00089 nClusterCols = pHdr->nColumn;
00090 setHdrOffsets(pHdr);
00091
00092
00093
00094 callTrace("Cluster Page Dump - PageId %ld", pageId);
00095 callTrace("-----------------------------");
00096 callTrace("Header");
00097 callTrace("------");
00098 callTrace("nColumn: %5u", nClusterCols);
00099 callTrace("firstRid: %5u", opaqueToInt(pHdr->firstRID));
00100 callTrace("oBatch: %5u", pHdr->oBatch);
00101 callTrace("nBatch: %5u", pHdr->nBatch);
00102 for (i = 0; i < nClusterCols; i++) {
00103 callTrace("lastVal[%d]: %5u", i, lastVal[i]);
00104 callTrace("firstVal[%d]: %5u", i, firstVal[i]);
00105 callTrace("nVal[%d]: %5u", i, nVal[i]);
00106 callTrace("delta[%d]: %5u", i, delta[i]);
00107 }
00108
00109 callTrace("#############################################################");
00110
00111
00112
00113 pBatch = (PLcsBatchDir) (pBlock + pHdr->oBatch);
00114 for (i = 0; i < pHdr->nBatch; i++) {
00115
00116
00117 int col = i % nClusterCols;
00118 uint16_t deltaVal = delta[col];
00119
00120 switch (pBatch[i].mode) {
00121 case LCS_COMPRESSED:
00122 mode = "Compressed";
00123 break;
00124 case LCS_VARIABLE:
00125 mode = "Variable";
00126 break;
00127 case LCS_FIXED:
00128 mode = "Fixed";
00129 break;
00130 default:
00131 permAssert(false);
00132 }
00133 callTrace("Batch #%2u (%s)", i + 1, mode);
00134 callTrace("--------------------");
00135 callTrace("mode: %5u", pBatch[i].mode);
00136 callTrace("nRow: %5u", pBatch[i].nRow);
00137 callTrace("nVal: %5u", pBatch[i].nVal);
00138 callTrace("nValHighMark: %5u", pBatch[i].nValHighMark);
00139 callTrace("oVal: %5u", pBatch[i].oVal);
00140 callTrace("oLastValHighMark: %5u", pBatch[i].oLastValHighMark);
00141 callTrace("recSize: %5u", pBatch[i].recSize);
00142
00143 if (pBatch[i].mode == LCS_COMPRESSED) {
00144 nBits = calcWidth(pBatch[i].nVal);
00145
00146
00147 iV = bitVecWidth(nBits, w);
00148
00149
00150 pBit = pBlock + pBatch[i].oVal + pBatch[i].nVal * sizeof(uint16_t);
00151
00152
00153 bitVecPtr(pBatch[i].nRow, iV, w, p, pBit);
00154
00155 callTrace("Rows");
00156 callTrace("----");
00157
00158 for (j = 0; j < pBatch[i].nRow;) {
00159 char buf[lnLen + 1];
00160 int bufidx = 0;
00161
00162 buf[0] = 0;
00163 count = min(uint(pBatch[i].nRow - j), MaxReadBatch);
00164
00165 readBitVecs(v, iV, w, p, j, count);
00166
00167 for (k = 0; k < count; k++, j++) {
00168 if ((j % 8) == 0) {
00169 if (j > 0) {
00170 callTrace("%s", buf);
00171 }
00172 sprintf(buf, "%5u: ", j);
00173 bufidx = 7;
00174 }
00175
00176 sprintf(buf + bufidx, "%5u ", (uint) v[k]);
00177 bufidx += 6;
00178 }
00179 callTrace("%s", buf);
00180 }
00181
00182 callTrace("Batch Values");
00183 callTrace("------------");
00184 pO = (uint16_t *) (pBlock + pBatch[i].oVal);
00185 for (j = 0; j < pBatch[i].nVal; j++) {
00186 fprintVal(j, pBlock + pO[j] - deltaVal, col);
00187 }
00188
00189 } else if (pBatch[i].mode == LCS_FIXED) {
00190
00191 callTrace("Fixed Size Rows");
00192 callTrace("---------------");
00193 pR = pBlock + pBatch[i].oVal;
00194 for (j = 0; j < pBatch[i].nRow; j++) {
00195 fprintVal(j, pR, col);
00196 pR += pBatch[i].recSize;
00197 }
00198 } else {
00199
00200 callTrace("Variable Size Rows");
00201 callTrace("------------------");
00202 pO = (uint16_t *) (pBlock + pBatch[i].oVal);
00203 for (j = 0; j < pBatch[i].nRow; j++) {
00204 fprintVal(j, pBlock + pO[j] - deltaVal, col);
00205 }
00206 }
00207 callTrace("#############################################################");
00208 }
00209
00210
00211
00212 callTrace("Value List at the Bottom of the Page");
00213 callTrace("------------------------------------");
00214 for (i = 0; i < nClusterCols; i++) {
00215 callTrace("Column #%2u", i);
00216 callTrace("------------");
00217 if (lastVal[i] < szBlock) {
00218 pR = pBlock + lastVal[i];
00219 for (j = nVal[i]; j > 0; j--) {
00220 pR = fprintVal(j, pR, i);
00221 }
00222 } else {
00223 callTrace("NONE.");
00224 }
00225 }
00226 }
00227
00228
00229 void LcsClusterDump::callTrace(const char *format, ...)
00230 {
00231 char buf[lnLen + 1];
00232 string str;
00233 va_list args;
00234
00235 va_start(args, format);
00236 vsprintf(buf, format, args);
00237 va_end(args);
00238
00239 str += buf;
00240 FENNEL_TRACE(traceLevel, str);
00241 }
00242
00243
00244 PBuffer LcsClusterDump::fprintVal(uint idx, PBuffer pV, uint col)
00245 {
00246 uint j, sz, k, l;
00247 PBuffer p = pV;
00248 char st[lnLen + 1];
00249
00250 st[lnLen] = 0;
00251 memset(st, ' ', lnLen);
00252 callTrace("%05u:", idx);
00253
00254 UnalignedAttributeAccessor attrAccessor(colTupleDesc[col]);
00255 sz = attrAccessor.getStoredByteCount(p);
00256 l = sprintf(st + lnValIdx, "%4u: ", sz);
00257 st[lnValIdx + l] = 0;
00258
00259 for (j = 0 ; j < sz; j++) {
00260 if (j && ((j % nByte) == 0)) {
00261 callTrace("%s", st);
00262 memset(st, ' ', lnLen);
00263 }
00264
00265 k = oByte + lnByte * (j % nByte);
00266 l = sprintf(st + k, "%2X ", p[j]);
00267 st[k + l] = ' ';
00268 st[oStr + (j % nByte)] = isprint(p[j]) ? p[j] : '.';
00269 }
00270
00271 callTrace("%s", st);
00272
00273 p += sz;
00274 return p;
00275 }
00276
00277 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/lucidera/colstore/LcsClusterDump.cpp#15 $");
00278
00279