// this runs in async thread
void StorageAsyncBulkCursor::AsyncReadFileChunk()
{
    StorageChunkReader      reader;
    StorageDataPage*        dataPage;
    StorageAsyncBulkResult* result;
    Callable                onNextChunk = MFUNC(StorageAsyncBulkCursor, OnNextChunk);
    
    reader.Open(chunkName, MAX_PRELOAD_THRESHOLD);
    
    lastResult = NULL;
    result = new StorageAsyncBulkResult(this);
    dataPage = reader.FirstDataPage();
    
    while (dataPage != NULL)
    {
        // rate control
        while (lastResult != NULL || env->yieldThreads || env->asyncGetThread->GetNumPending() > 0)
        {
            MSleep(1);
        }

        if (isAborted || env->shuttingDown)
        {
            // abort cursor
            delete result;
            delete this;
            return;
        }
    
        TransferDataPage(result, dataPage);
        OnResult(result);
        
        result = new StorageAsyncBulkResult(this);
        dataPage = reader.NextDataPage();
    }
    
    OnResult(result);
    IOProcessor::Complete(&onNextChunk);
}
Exemple #2
0
void cDebugFile::Output(string sKeyList /* =  */, eOutPut eOutType /* = All */)
{
    std::vector<string> vecKey;
	ParseName(vecKey, sKeyList);

	ostringstream osFile;
    int64 nResult(0); // >0增加  <0减少  =0不变
    for (size_t i = 0; i < m_keyPos; ++i)
    {
        stKeyInfo& info = m_vecKey[i];

        if (!vecKey.empty()
            && find(vecKey.begin(), vecKey.end(), info.key) == vecKey.end())
        {
            continue;
        }

        switch (info.type){
		case v_uint8:{
				nResult = int16(*(uint8*)info.pObj) - int16(*(uint8*)info.pOld); //可为-255
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(uint8*)info.pObj << "(" << *(uint8*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_uint16:{
				nResult = int32(*(uint16*)info.pObj) - int32(*(uint16*)info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(uint16*)info.pObj << "(" << *(uint16*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_uint32:{
				nResult = int64(*(uint32*)info.pObj) - int64(*(uint32*)info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(uint32*)info.pObj << "(" << *(uint32*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_uint64:{
				nResult = (*(int64*)info.pObj) - (*(int64*)info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(int64*)info.pObj << "(" << *(int64*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_int8:{
				nResult = int16(*(int8*)info.pObj) - int16(*(int8*)info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(int8*)info.pObj << "(" << *(int8*)info.pOld << ")" << ";\r\n";
				}
			}
			break;
		case v_int16:{
				nResult = int32(*(int16*)info.pObj) - int32(*(int16*)info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(int16*)info.pObj << "(" << *(int16*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_int32:{
				nResult = int64(*(int32*)info.pObj) - int64(*(int32*)info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(int32*)info.pObj << "(" << *(int32*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_int64:{
				nResult = (*(int64*)info.pObj) - (*(int64*)info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(int64*)info.pObj << "(" << *(int64*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_float:{
				float dif = (*(float*)info.pObj) - (*(float*)info.pOld);
				if (OnResult(eOutType, dif == 0 ? 0 : (dif>0 ? 1 : -1), info.key, osFile))
				{
					osFile << " = " << *(float*)info.pObj << "(" << *(float*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_double:{
				double dif = (*(double*)info.pObj) - (*(double*)info.pOld);
				if (OnResult(eOutType, dif == 0 ? 0 : (dif>0 ? 1 : -1), info.key, osFile))
				{
					osFile << " = " << *(double*)info.pObj << "(" << *(double*)info.pOld << ")" << ";\r\n";
				}
			}break;
		case v_string:{
				nResult = strcmp(info.pObj, info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << info.pObj << "(" << info.pOld << ")" << ";\r\n";
				}
			}break;
		default:{
				nResult = int64(*(int32*)info.pObj) - int64(*(int32*)info.pOld);
				if (OnResult(eOutType, nResult, info.key, osFile))
				{
					osFile << " = " << *(int32*)info.pObj << "(" << *(int32*)info.pOld << ")" << ";\r\n";
				}
			}break;
        }
    }
	osFile << "\r\n";

    WriteToFile(m_sFileName, osFile);
}