1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

clang format apply

This commit is contained in:
Leonid Fedorov
2022-01-21 16:43:49 +00:00
parent 6b6411229f
commit 04752ec546
1376 changed files with 393460 additions and 412662 deletions

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: we_cache.cpp 33 2006-10-30 13:45:13Z wzhou $
*
******************************************************************************************/
* $Id: we_cache.cpp 33 2006-10-30 13:45:13Z wzhou $
*
******************************************************************************************/
/** @file */
#include <we_cache.h>
@ -27,15 +27,14 @@ using namespace std;
namespace WriteEngine
{
CacheControl* Cache::m_cacheParam = NULL;
FreeBufList* Cache::m_freeList = NULL;
CacheMap* Cache::m_lruList = NULL;
CacheMap* Cache::m_writeList = NULL;
CacheControl* Cache::m_cacheParam = NULL;
FreeBufList* Cache::m_freeList = NULL;
CacheMap* Cache::m_lruList = NULL;
CacheMap* Cache::m_writeList = NULL;
#ifdef _MSC_VER
__declspec(dllexport)
#endif
bool Cache::m_useCache = false;
bool Cache::m_useCache = false;
/***********************************************************
* DESCRIPTION:
* Clear all list and free memory
@ -44,47 +43,47 @@ bool Cache::m_useCache = false;
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
void Cache::clear()
void Cache::clear()
{
CacheMapIt it;
BlockBuffer* block;
size_t i;
CacheMapIt it;
BlockBuffer* block;
size_t i;
// free list
if ( m_freeList != NULL )
// free list
if (m_freeList != NULL)
{
for (i = 0; i < m_freeList->size(); i++)
{
for ( i = 0; i < m_freeList->size(); i++ )
{
block = m_freeList->at(i);
block->clear();
}
block = m_freeList->at(i);
block->clear();
}
}
// LRU list
if (m_lruList != NULL)
{
for (it = m_lruList->begin(); it != m_lruList->end(); it++)
{
block = it->second;
block->clear();
m_freeList->push_back(block);
}
// LRU list
if ( m_lruList != NULL )
{
for ( it = m_lruList->begin(); it != m_lruList->end(); it++ )
{
block = it->second;
block->clear();
m_freeList->push_back( block );
}
m_lruList->clear();
}
m_lruList->clear();
// Write list
if (m_writeList != NULL)
{
for (it = m_writeList->begin(); it != m_writeList->end(); it++)
{
block = it->second;
block->clear();
m_freeList->push_back(block);
}
// Write list
if ( m_writeList != NULL )
{
for ( it = m_writeList->begin(); it != m_writeList->end(); it++ )
{
block = it->second;
block->clear();
m_freeList->push_back( block );
}
m_writeList->clear();
}
m_writeList->clear();
}
}
/***********************************************************
@ -95,50 +94,50 @@ void Cache::clear()
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
int Cache::flushCache()
int Cache::flushCache()
{
bool bHasReadBlock = false;
BlockBuffer* curBuf;
bool bHasReadBlock = false;
BlockBuffer* curBuf;
// add lock here
if ( m_lruList && m_lruList->size() > 0 )
// add lock here
if (m_lruList && m_lruList->size() > 0)
{
bHasReadBlock = true;
for (CacheMapIt it = m_lruList->begin(); it != m_lruList->end(); it++)
{
bHasReadBlock = true;
for ( CacheMapIt it = m_lruList->begin(); it != m_lruList->end(); it++ )
{
curBuf = it->second;
curBuf->clear();
m_freeList->push_back( curBuf );
}
m_lruList->clear();
curBuf = it->second;
curBuf->clear();
m_freeList->push_back(curBuf);
}
// must write to disk first
if ( m_writeList && m_writeList->size() > 0 )
{
if ( !bHasReadBlock )
for ( CacheMapIt it = m_writeList->begin(); it != m_writeList->end(); it++ )
{
curBuf = it->second;
curBuf->clear();
m_freeList->push_back( curBuf );
}
else
for ( CacheMapIt it = m_writeList->begin(); it != m_writeList->end(); it++ )
{
curBuf = it->second;
(*curBuf).block.dirty = false;
processCacheMap( m_lruList, curBuf, INSERT );
}
m_lruList->clear();
}
m_writeList->clear();
// must write to disk first
if (m_writeList && m_writeList->size() > 0)
{
if (!bHasReadBlock)
for (CacheMapIt it = m_writeList->begin(); it != m_writeList->end(); it++)
{
curBuf = it->second;
curBuf->clear();
m_freeList->push_back(curBuf);
}
else
for (CacheMapIt it = m_writeList->begin(); it != m_writeList->end(); it++)
{
curBuf = it->second;
(*curBuf).block.dirty = false;
processCacheMap(m_lruList, curBuf, INSERT);
}
} // end of if( m_writeList->size()
m_writeList->clear();
// add unlock here
return NO_ERROR;
} // end of if( m_writeList->size()
// add unlock here
return NO_ERROR;
}
/***********************************************************
@ -149,63 +148,63 @@ int Cache::flushCache()
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
void Cache::freeMemory()
void Cache::freeMemory()
{
CacheMapIt it;
BlockBuffer* block;
size_t i;
CacheMapIt it;
BlockBuffer* block;
size_t i;
// free list
if ( m_freeList != NULL )
// free list
if (m_freeList != NULL)
{
for (i = 0; i < m_freeList->size(); i++)
{
for ( i = 0; i < m_freeList->size(); i++ )
{
block = m_freeList->at(i);
block->freeMem();
delete block;
}
m_freeList->clear();
delete m_freeList;
m_freeList = NULL;
block = m_freeList->at(i);
block->freeMem();
delete block;
}
// LRU list
if ( m_lruList != NULL )
{
for ( it = m_lruList->begin(); it != m_lruList->end(); it++ )
{
block = it->second;
block->freeMem();
delete block;
}
m_freeList->clear();
delete m_freeList;
m_freeList = NULL;
}
m_lruList->clear();
delete m_lruList;
m_lruList = NULL;
// LRU list
if (m_lruList != NULL)
{
for (it = m_lruList->begin(); it != m_lruList->end(); it++)
{
block = it->second;
block->freeMem();
delete block;
}
// Write list
if ( m_writeList != NULL )
{
for ( it = m_writeList->begin(); it != m_writeList->end(); it++ )
{
block = it->second;
block->freeMem();
delete block;
}
m_lruList->clear();
delete m_lruList;
m_lruList = NULL;
}
m_writeList->clear();
delete m_writeList;
m_writeList = NULL;
// Write list
if (m_writeList != NULL)
{
for (it = m_writeList->begin(); it != m_writeList->end(); it++)
{
block = it->second;
block->freeMem();
delete block;
}
// param
if ( m_cacheParam != NULL )
{
delete m_cacheParam;
m_cacheParam = NULL;
}
m_writeList->clear();
delete m_writeList;
m_writeList = NULL;
}
// param
if (m_cacheParam != NULL)
{
delete m_cacheParam;
m_cacheParam = NULL;
}
}
/***********************************************************
@ -216,30 +215,24 @@ void Cache::freeMemory()
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
int Cache::getListSize( const CacheListType listType )
int Cache::getListSize(const CacheListType listType)
{
int size = 0;
if ( !m_useCache )
return size;
switch ( listType )
{
case FREE_LIST:
size = m_freeList->size();
break;
case LRU_LIST:
size = m_lruList->size();
break;
case WRITE_LIST:
default:
size = m_writeList->size();
break;
}
int size = 0;
if (!m_useCache)
return size;
switch (listType)
{
case FREE_LIST: size = m_freeList->size(); break;
case LRU_LIST: size = m_lruList->size(); break;
case WRITE_LIST:
default: size = m_writeList->size(); break;
}
return size;
}
/***********************************************************
@ -252,28 +245,28 @@ int Cache::getListSize( const CacheListType listType )
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
void Cache::init( const int totalBlock, const int chkPoint, const int pctFree )
void Cache::init(const int totalBlock, const int chkPoint, const int pctFree)
{
BlockBuffer* buffer;
BlockBuffer* buffer;
if ( m_cacheParam && m_freeList && m_lruList && m_writeList )
return;
if (m_cacheParam && m_freeList && m_lruList && m_writeList)
return;
m_cacheParam = new CacheControl();
m_cacheParam->totalBlock = totalBlock;
m_cacheParam->checkInterval = chkPoint;
m_cacheParam->pctFree = pctFree;
m_cacheParam = new CacheControl();
m_cacheParam->totalBlock = totalBlock;
m_cacheParam->checkInterval = chkPoint;
m_cacheParam->pctFree = pctFree;
m_freeList = new FreeBufList();
m_lruList = new CacheMap();
m_writeList = new CacheMap();
m_freeList = new FreeBufList();
m_lruList = new CacheMap();
m_writeList = new CacheMap();
for ( int i = 0; i < m_cacheParam->totalBlock; i++ )
{
buffer = new BlockBuffer();
buffer->init();
m_freeList->push_back( buffer );
}
for (int i = 0; i < m_cacheParam->totalBlock; i++)
{
buffer = new BlockBuffer();
buffer->init();
m_freeList->push_back(buffer);
}
}
/***********************************************************
@ -287,30 +280,30 @@ void Cache::init( const int totalBlock, const int chkPoint, const int pctFree )
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
int Cache::insertLRUList( CommBlock& cb, const uint64_t lbid, const uint64_t fbo, const unsigned char* buf )
int Cache::insertLRUList(CommBlock& cb, const uint64_t lbid, const uint64_t fbo, const unsigned char* buf)
{
BlockBuffer* buffer;
vector<BlockBuffer*>::iterator it;
BlockBuffer* buffer;
vector<BlockBuffer*>::iterator it;
if ( m_freeList->size() == 0 )
return ERR_FREE_LIST_EMPTY;
if (m_freeList->size() == 0)
return ERR_FREE_LIST_EMPTY;
// make sure flush first if necessary
it = m_freeList->begin();
buffer = *it;
memcpy( (*buffer).block.data, buf, BYTE_PER_BLOCK );
(*buffer).listType = LRU_LIST;
(*buffer).block.lbid = lbid;
(*buffer).block.fbo = fbo;
(*buffer).block.dirty = false;
(*buffer).block.hitCount = 1;
(*buffer).cb.file.oid = cb.file.oid;
(*buffer).cb.file.pFile = cb.file.pFile;
// make sure flush first if necessary
it = m_freeList->begin();
buffer = *it;
memcpy((*buffer).block.data, buf, BYTE_PER_BLOCK);
(*buffer).listType = LRU_LIST;
(*buffer).block.lbid = lbid;
(*buffer).block.fbo = fbo;
(*buffer).block.dirty = false;
(*buffer).block.hitCount = 1;
(*buffer).cb.file.oid = cb.file.oid;
(*buffer).cb.file.pFile = cb.file.pFile;
RETURN_ON_ERROR( processCacheMap( m_lruList, buffer, INSERT ) );
m_freeList->erase( it );
RETURN_ON_ERROR(processCacheMap(m_lruList, buffer, INSERT));
m_freeList->erase(it);
return NO_ERROR;
return NO_ERROR;
}
/***********************************************************
@ -322,29 +315,29 @@ int Cache::insertLRUList( CommBlock& cb, const uint64_t lbid, const uint64_t fb
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
int Cache::loadCacheBlock( const CacheKey& key, unsigned char* buf )
int Cache::loadCacheBlock(const CacheKey& key, unsigned char* buf)
{
BlockBuffer* buffer;
CacheMapIt iter;
BlockBuffer* buffer;
CacheMapIt iter;
iter = m_lruList->find( key );
iter = m_lruList->find(key);
if ( iter != m_lruList->end() )
buffer = iter->second;
if (iter != m_lruList->end())
buffer = iter->second;
else
{
iter = m_writeList->find(key);
if (iter != m_writeList->end())
buffer = iter->second;
else
{
iter = m_writeList->find( key );
return ERR_CACHE_KEY_NOT_EXIST;
}
if ( iter != m_writeList->end() )
buffer = iter->second;
else
return ERR_CACHE_KEY_NOT_EXIST;
}
memcpy(buf, (*buffer).block.data, BYTE_PER_BLOCK);
(*buffer).block.hitCount++;
memcpy( buf, (*buffer).block.data, BYTE_PER_BLOCK );
(*buffer).block.hitCount++;
return NO_ERROR;
return NO_ERROR;
}
/***********************************************************
@ -356,37 +349,36 @@ int Cache::loadCacheBlock( const CacheKey& key, unsigned char* buf )
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
int Cache::modifyCacheBlock( const CacheKey& key, const unsigned char* buf )
int Cache::modifyCacheBlock(const CacheKey& key, const unsigned char* buf)
{
BlockBuffer* buffer;
CacheMapIt iter;
BlockBuffer* buffer;
CacheMapIt iter;
iter = m_lruList->find( key );
iter = m_lruList->find(key);
if ( iter != m_lruList->end() )
{
buffer = iter->second;
(*buffer).listType = WRITE_LIST;
(*buffer).block.dirty = true;
if (iter != m_lruList->end())
{
buffer = iter->second;
(*buffer).listType = WRITE_LIST;
(*buffer).block.dirty = true;
(*m_writeList)[key] = iter->second;
m_lruList->erase( iter );
(*m_writeList)[key] = iter->second;
m_lruList->erase(iter);
}
else
{
iter = m_writeList->find(key);
}
if (iter != m_writeList->end())
buffer = iter->second;
else
{
iter = m_writeList->find( key );
return ERR_CACHE_KEY_NOT_EXIST;
}
if ( iter != m_writeList->end() )
buffer = iter->second;
else
return ERR_CACHE_KEY_NOT_EXIST;
}
memcpy((*buffer).block.data, buf, BYTE_PER_BLOCK);
(*buffer).block.hitCount++;
memcpy( (*buffer).block.data, buf, BYTE_PER_BLOCK );
(*buffer).block.hitCount++;
return NO_ERROR;
return NO_ERROR;
}
/***********************************************************
@ -397,35 +389,35 @@ int Cache::modifyCacheBlock( const CacheKey& key, const unsigned char* buf )
* RETURN:
* none
***********************************************************/
void Cache::printCacheList()
void Cache::printCacheList()
{
BlockBuffer* buffer;
int i = 0;
BlockBuffer* buffer;
int i = 0;
if ( !m_useCache )
return;
if (!m_useCache)
return;
cout << "\nFree List has " << m_freeList->size() << " elements" << endl;
cout << "LRU List has " << m_lruList->size() << " elements" << endl;
cout << "\nFree List has " << m_freeList->size() << " elements" << endl;
cout << "LRU List has " << m_lruList->size() << " elements" << endl;
for ( CacheMapIt it = m_lruList->begin(); it != m_lruList->end(); it++ )
{
buffer = it->second;
cout << "\t[" << i++ << "] key=" << it->first << " listType=" << buffer->listType
<< " oid=" << (*buffer).cb.file.oid << " fbo=" << (*buffer).block.fbo
<< " dirty=" << (*buffer).block.dirty << " hitCount=" << (*buffer).block.hitCount << endl;
}
for (CacheMapIt it = m_lruList->begin(); it != m_lruList->end(); it++)
{
buffer = it->second;
cout << "\t[" << i++ << "] key=" << it->first << " listType=" << buffer->listType
<< " oid=" << (*buffer).cb.file.oid << " fbo=" << (*buffer).block.fbo
<< " dirty=" << (*buffer).block.dirty << " hitCount=" << (*buffer).block.hitCount << endl;
}
i = 0;
cout << "Write List has " << m_writeList->size() << " elements" << endl;
i = 0;
cout << "Write List has " << m_writeList->size() << " elements" << endl;
for ( CacheMapIt it = m_writeList->begin(); it != m_writeList->end(); it++ )
{
buffer = it->second;
cout << "\t[" << i++ << "] key=" << it->first << " listType=" << buffer->listType
<< " oid=" << (*buffer).cb.file.oid << " fbo=" << (*buffer).block.fbo
<< " dirty=" << (*buffer).block.dirty << " hitCount=" << (*buffer).block.hitCount << endl;
}
for (CacheMapIt it = m_writeList->begin(); it != m_writeList->end(); it++)
{
buffer = it->second;
cout << "\t[" << i++ << "] key=" << it->first << " listType=" << buffer->listType
<< " oid=" << (*buffer).cb.file.oid << " fbo=" << (*buffer).block.fbo
<< " dirty=" << (*buffer).block.dirty << " hitCount=" << (*buffer).block.hitCount << endl;
}
}
/***********************************************************
@ -437,34 +429,31 @@ void Cache::printCacheList()
* RETURN:
* NO_ERROR if success, other otherwise
***********************************************************/
int Cache::processCacheMap( CacheMap* map, BlockBuffer* buffer, OpType opType )
int Cache::processCacheMap(CacheMap* map, BlockBuffer* buffer, OpType opType)
{
RETURN_ON_NULL( buffer, ERR_NULL_BLOCK );
CacheMapIt iter;
RETURN_ON_NULL(buffer, ERR_NULL_BLOCK);
CacheMapIt iter;
CacheKey key = getCacheKey( buffer );
iter = map->find( key );
CacheKey key = getCacheKey(buffer);
iter = map->find(key);
// only handle insert and delete
if ( iter == map->end() )
{
if ( opType == INSERT )
(*map)[key] = buffer;
else
return ERR_CACHE_KEY_NOT_EXIST;
}
// only handle insert and delete
if (iter == map->end())
{
if (opType == INSERT)
(*map)[key] = buffer;
else
{
if ( opType == INSERT )
return ERR_CACHE_KEY_EXIST;
else
map->erase( iter );
}
return ERR_CACHE_KEY_NOT_EXIST;
}
else
{
if (opType == INSERT)
return ERR_CACHE_KEY_EXIST;
else
map->erase(iter);
}
return NO_ERROR;
return NO_ERROR;
}
} //end of namespace
} // namespace WriteEngine