int SharedDataManager::setData(TreeDescriptor treeId, int nid, char dataType, int numSamples, char *data, int size) //Write data indexed by nid { lock.lock(); SharedMemNode *node = sharedTree.find(treeId, nid); if(!node) //No data has been written in the cache yet { SharedMemNodeData nodeData; nodeData.setNid(treeId, nid); sharedTree.insert(&nodeData); node = sharedTree.find(treeId, nid); } if(node) { SharedMemNodeData *nodeData = node->getData() ; nodeData->free(&allocationManager); char *currData = allocationManager.allocateShared(size); memcpy(currData, data, size); nodeData->setData((char *)currData, size); nodeData->setDataInfo(dataType, numSamples); CallbackManager *callback = node->getData()->getCallbackManager(); if(callback) callback->callCallback(); lock.unlock(); return 1; } else { lock.unlock(); return 0; } }
void SharedDataManager::setSerializedData(TreeDescriptor treeId, int nid, char *serializedData, int dataLen) { lock.lock(); SharedMemNode *node = sharedTree.find(treeId, nid); if(!node) //No data has been written in the cache yet { SharedMemNodeData nodeData; nodeData.setNid(treeId, nid); sharedTree.insert(&nodeData); node = sharedTree.find(treeId, nid); } if(node) { SharedMemNodeData *nodeData = node->getData(); nodeData->free(&allocationManager); nodeData->initialize(serializedData, &allocationManager); CallbackManager *callback = node->getData()->getCallbackManager(); if(callback) callback->callCallback(); } lock.unlock(); }
int SharedDataManager::updateSegment(TreeDescriptor treeId, int nid, int idx, char *start, int startSize, char *end, int endSize, char *dim, int dimSize) { Segment *segment; lock.lock(); SharedMemNode *node = sharedTree.find(treeId, nid); if(node) { SharedMemNodeData *nodeData = node->getData(); if(!nodeData->isSegmented()) { lock.unlock(); return 0; } int numSegments = nodeData->getNumSegments(); if(idx > numSegments || idx < 0) { lock.unlock(); return 0; } segment = nodeData->getSegmentAt(idx); char *currPtr; int currSize; segment->getStart(&currPtr, &currSize); if(startSize > 0) { if(currSize > 0) allocationManager.deallocateShared((char *)currPtr, currSize); currPtr = allocationManager.allocateShared(startSize); memcpy(currPtr, start, startSize); segment->setStart(currPtr, startSize); } if(endSize > 0) { segment->getEnd(&currPtr, &currSize); if(currSize > 0) allocationManager.deallocateShared((char *)currPtr, currSize); currPtr = allocationManager.allocateShared(endSize); memcpy(currPtr, end, endSize); segment->setEnd(currPtr, endSize); } if(dimSize > 0) { segment->getDim(&currPtr, &currSize); if(currSize > 0) allocationManager.deallocateShared((char *)currPtr, currSize); currPtr = allocationManager.allocateShared(dimSize); memcpy(currPtr, dim, dimSize); segment->setDim(currPtr, dimSize); } CallbackManager *callback = node->getData()->getCallbackManager(); if(callback) callback->callCallback(); lock.unlock(); return 1; } lock.unlock(); return 0; }
/* //Return Shape and type information. The coding is the following: //1) data type //2) item size in bytes //3) number of dimensions //4) total dimension in bytes //The remaining elements are the dimension limits */ int SharedDataManager::appendSegmentData(TreeDescriptor treeId, int nid, int *bounds, int boundsSize, char *data, int dataSize, int idx, int startIdx, bool isTimestamped, _int64 *timestamps, int numTimestamps, int *segmentFilled, int *retIdx) { int numSegments; int *shape; int shapeSize; char *segmentData; int segmentSize; lock.lock(); SharedMemNode *node = sharedTree.find(treeId, nid); if(!node) { SharedMemNodeData nodeData; nodeData.setNid(treeId, nid); nodeData.setSegmented(true); sharedTree.insert(&nodeData); node = sharedTree.find(treeId, nid); } if(node) { SharedMemNodeData *nodeData = node->getData(); numSegments = nodeData->getNumSegments(); if(numSegments == 0) //May happen the first time putRow is called { lock.unlock(); // printf("APPENDSEGMENT DATA: NO SEGMENTS"); return TRUNCATED; } if(idx >= numSegments || numSegments == 0) { lock.unlock(); // printf("APPENDSEGMENT DATA: BAD INDEX"); return BAD_INDEX; } Segment *segment = nodeData->getSegmentAt(idx); /* if(!segment->isTimestamped()) { lock.unlock(); return 0; } */ segment->getShape((char **)&shape, &shapeSize); //Check Shape. Meaning of bound array: // 1) data type // 2) item size in bytes // 3) number of dimensions // 4) total dimension in bytes // The remaining elements are the dimension limits if(bounds[0] != shape[0]) { lock.unlock(); // printf("APPENDSEGMENT DATA: BAD TYPE %d %d\n", bounds[0], shape[0]); return BAD_TYPE; } if(bounds[2] < shape[2] - 1 || bounds[2] > shape[2]) { lock.unlock(); // printf("APPENDSEGMENT DATA: BAD TYPE 1"); return BAD_SHAPE; } for(int i = 0; i < shape[2] - 1; i++) { if(bounds[4 + i] != shape[4 + i]) { lock.unlock(); // printf("APPENDSEGMENT DATA: BAD SHAPE"); return BAD_SHAPE; } } int currSegmentSize = segment->getCurrDataSize(); segment->getData((char **)&segmentData, &segmentSize); if(startIdx < 0) { int leftSize = segmentSize - currSegmentSize; if(dataSize > leftSize) { lock.unlock(); // printf("APPENDSEGMENT DATA: DATASIZE > LEFT SIZE"); return TRUNCATED; } if(leftSize == dataSize) *segmentFilled = 1; else *segmentFilled = 0; memcpy(&segmentData[currSegmentSize], data, dataSize); segment->setCurrDataSize(currSegmentSize + dataSize); if(isTimestamped) segment->appendTimestamps(timestamps, numTimestamps); *retIdx = numSegments - 1; CallbackManager *callback = node->getData()->getCallbackManager(); if(callback) callback->callCallback(); lock.unlock(); return 1; } else { int itemSize = bounds[3]; //Total size of a data item (array) int startOfs = startIdx * itemSize; int leftSize = segmentSize - startOfs; if(dataSize > leftSize) { lock.unlock(); // printf("APPENDSEGMENT DATA: DATASIZE > LEFT SIZE"); return TRUNCATED; } if(leftSize == dataSize) *segmentFilled = 1; else *segmentFilled = 0; memcpy(&segmentData[startOfs], data, dataSize); *retIdx = numSegments - 1; //Segment size does not change CallbackManager *callback = node->getData()->getCallbackManager(); if(callback) callback->callCallback(); lock.unlock(); return 1; } } lock.unlock(); return 0; }