1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-10-21 11:33:43 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@@ -20,10 +20,10 @@
* We want free and open source software applications under certain
* licenses to be able to use the GPL-licensed InfiniDB idbhdfs
* libraries despite the fact that not all such FOSS licenses are
* compatible with version 2 of the GNU General Public License.
* Therefore there are special exceptions to the terms and conditions
* of the GPLv2 as applied to idbhdfs libraries, which are
* identified and described in more detail in the FOSS License
* compatible with version 2 of the GNU General Public License.
* Therefore there are special exceptions to the terms and conditions
* of the GPLv2 as applied to idbhdfs libraries, which are
* identified and described in more detail in the FOSS License
* Exception in the file utils/idbhdfs/FOSS-EXCEPTION.txt
*/
@@ -46,112 +46,114 @@ namespace idbdatafile
{
HdfsFileSystem::HdfsFileSystem() :
IDBFileSystem( IDBFileSystem::HDFS )
IDBFileSystem( IDBFileSystem::HDFS )
{
m_fs = HdfsFsCache::fs();
m_fs = HdfsFsCache::fs();
}
HdfsFileSystem::~HdfsFileSystem()
{
}
int HdfsFileSystem::mkdir(const char *pathname)
int HdfsFileSystem::mkdir(const char* pathname)
{
// todo: may need to do hdfsChmod to set mode, but for now assume not necessary
int ret = hdfsCreateDirectory(m_fs,pathname);
// todo: may need to do hdfsChmod to set mode, but for now assume not necessary
int ret = hdfsCreateDirectory(m_fs, pathname);
if( ret != 0 )
{
if ( ret != 0 )
{
std::ostringstream oss;
oss << "hdfsCreateDirectory failed for: " << pathname << ", errno: " << errno << "," << strerror(errno) << endl;
oss << "hdfsCreateDirectory failed for: " << pathname << ", errno: " << errno << "," << strerror(errno) << endl;
IDBLogger::syslog(oss.str(), logging::LOG_TYPE_ERROR);
}
}
if( IDBLogger::isEnabled() )
IDBLogger::logFSop( HDFS, "mkdir", pathname, this, ret);
if ( IDBLogger::isEnabled() )
IDBLogger::logFSop( HDFS, "mkdir", pathname, this, ret);
return ret;
return ret;
}
int HdfsFileSystem::remove(const char *pathname)
int HdfsFileSystem::remove(const char* pathname)
{
int ret = 0;
int ret = 0;
// the HDFS API doesn't like calling hdfsDelete with a path that does
// not exist. We catch this case and return 0 - this is based on
// boost::filesystem behavior where removing an invalid path is
// treated as a successful operation
if( exists( pathname ) )
{
// the HDFS API doesn't like calling hdfsDelete with a path that does
// not exist. We catch this case and return 0 - this is based on
// boost::filesystem behavior where removing an invalid path is
// treated as a successful operation
if ( exists( pathname ) )
{
#ifdef CDH4
ret = hdfsDelete(m_fs,pathname,1);
ret = hdfsDelete(m_fs, pathname, 1);
#else
ret = hdfsDelete(m_fs,pathname);
ret = hdfsDelete(m_fs, pathname);
#endif
}
}
if( IDBLogger::isEnabled() )
IDBLogger::logFSop( HDFS, "remove", pathname, this, ret);
if ( IDBLogger::isEnabled() )
IDBLogger::logFSop( HDFS, "remove", pathname, this, ret);
return ret;
return ret;
}
int HdfsFileSystem::rename(const char *oldpath, const char *newpath)
int HdfsFileSystem::rename(const char* oldpath, const char* newpath)
{
int ret = hdfsRename(m_fs, oldpath, newpath);
int ret = hdfsRename(m_fs, oldpath, newpath);
if( IDBLogger::isEnabled() )
IDBLogger::logFSop2( HDFS, "rename", oldpath, newpath, this, ret);
if ( IDBLogger::isEnabled() )
IDBLogger::logFSop2( HDFS, "rename", oldpath, newpath, this, ret);
return ret;
return ret;
}
off64_t HdfsFileSystem::size(const char* path) const
{
hdfsFileInfo* fileinfo;
fileinfo = hdfsGetPathInfo(m_fs,path);
off64_t retval = (fileinfo ? fileinfo->mSize : -1);
if( fileinfo )
hdfsFreeFileInfo(fileinfo,1);
hdfsFileInfo* fileinfo;
fileinfo = hdfsGetPathInfo(m_fs, path);
off64_t retval = (fileinfo ? fileinfo->mSize : -1);
if( IDBLogger::isEnabled() )
IDBLogger::logFSop( HDFS, "fs:size", path, this, retval);
if ( fileinfo )
hdfsFreeFileInfo(fileinfo, 1);
return retval;
if ( IDBLogger::isEnabled() )
IDBLogger::logFSop( HDFS, "fs:size", path, this, retval);
return retval;
}
size_t readFillBuffer(
idbdatafile::IDBDataFile* pFile,
char* buffer,
size_t bytesReq)
idbdatafile::IDBDataFile* pFile,
char* buffer,
size_t bytesReq)
{
char* pBuf = buffer;
ssize_t nBytes;
size_t bytesToRead = bytesReq;
size_t totalBytesRead = 0;
char* pBuf = buffer;
ssize_t nBytes;
size_t bytesToRead = bytesReq;
size_t totalBytesRead = 0;
while (1)
{
nBytes = pFile->read(pBuf, bytesToRead);
if (nBytes > 0)
totalBytesRead += nBytes;
else
break;
while (1)
{
nBytes = pFile->read(pBuf, bytesToRead);
if ((size_t)nBytes == bytesToRead)
break;
if (nBytes > 0)
totalBytesRead += nBytes;
else
break;
pBuf += nBytes;
bytesToRead = bytesToRead - (size_t)nBytes;
}
if ((size_t)nBytes == bytesToRead)
break;
return totalBytesRead;
pBuf += nBytes;
bytesToRead = bytesToRead - (size_t)nBytes;
}
return totalBytesRead;
}
off64_t HdfsFileSystem::compressedSize(const char *path) const
off64_t HdfsFileSystem::compressedSize(const char* path) const
{
IDBDataFile *pFile = NULL;
IDBDataFile* pFile = NULL;
size_t nBytes;
off64_t dataSize = 0;
@@ -167,7 +169,8 @@ off64_t HdfsFileSystem::compressedSize(const char *path) const
compress::IDBCompressInterface decompressor;
char hdr1[compress::IDBCompressInterface::HDR_BUF_LEN];
nBytes = readFillBuffer( pFile,hdr1,compress::IDBCompressInterface::HDR_BUF_LEN);
nBytes = readFillBuffer( pFile, hdr1, compress::IDBCompressInterface::HDR_BUF_LEN);
if ( nBytes != compress::IDBCompressInterface::HDR_BUF_LEN )
{
delete pFile;
@@ -183,7 +186,8 @@ off64_t HdfsFileSystem::compressedSize(const char *path) const
int64_t ptrSecSize = decompressor.getHdrSize(hdr1) - compress::IDBCompressInterface::HDR_BUF_LEN;
char* hdr2 = new char[ptrSecSize];
nBytes = readFillBuffer( pFile,hdr2,ptrSecSize);
nBytes = readFillBuffer( pFile, hdr2, ptrSecSize);
if ( (int64_t)nBytes != ptrSecSize )
{
delete[] hdr2;
@@ -194,6 +198,7 @@ off64_t HdfsFileSystem::compressedSize(const char *path) const
compress::CompChunkPtrList chunkPtrs;
int rc = decompressor.getPtrList(hdr2, ptrSecSize, chunkPtrs);
delete[] hdr2;
if (rc != 0)
{
delete pFile;
@@ -201,13 +206,15 @@ off64_t HdfsFileSystem::compressedSize(const char *path) const
}
unsigned k = chunkPtrs.size();
// last header's offset + length will be the data bytes
if (k < 1)
{
delete pFile;
return -1;
}
dataSize = chunkPtrs[k-1].first + chunkPtrs[k-1].second;
dataSize = chunkPtrs[k - 1].first + chunkPtrs[k - 1].second;
delete pFile;
return dataSize;
}
@@ -218,76 +225,83 @@ off64_t HdfsFileSystem::compressedSize(const char *path) const
}
}
bool HdfsFileSystem::exists(const char *pathname) const
bool HdfsFileSystem::exists(const char* pathname) const
{
int ret = hdfsExists(m_fs,pathname);
return ret == 0;
int ret = hdfsExists(m_fs, pathname);
return ret == 0;
}
int HdfsFileSystem::listDirectory(const char* pathname, std::list<std::string>& contents) const
{
// clear the return list
contents.erase( contents.begin(), contents.end() );
// clear the return list
contents.erase( contents.begin(), contents.end() );
int numEntries;
hdfsFileInfo* fileinfo;
if( !exists( pathname ) ) {
errno = ENOENT;
return -1;
}
int numEntries;
hdfsFileInfo* fileinfo;
// hdfs not happy if you call list directory on a path that does not exist
fileinfo = hdfsListDirectory(m_fs,pathname, &numEntries);
for( int i = 0; i < numEntries && fileinfo; ++i )
{
// hdfs returns a fully specified path name but we want to
// only return paths relative to the directory passed in.
boost::filesystem::path filepath( fileinfo[i].mName );
contents.push_back( filepath.filename().c_str() );
}
if( fileinfo )
hdfsFreeFileInfo(fileinfo, numEntries);
if ( !exists( pathname ) )
{
errno = ENOENT;
return -1;
}
return 0;
// hdfs not happy if you call list directory on a path that does not exist
fileinfo = hdfsListDirectory(m_fs, pathname, &numEntries);
for ( int i = 0; i < numEntries && fileinfo; ++i )
{
// hdfs returns a fully specified path name but we want to
// only return paths relative to the directory passed in.
boost::filesystem::path filepath( fileinfo[i].mName );
contents.push_back( filepath.filename().c_str() );
}
if ( fileinfo )
hdfsFreeFileInfo(fileinfo, numEntries);
return 0;
}
bool HdfsFileSystem::isDir(const char* pathname) const
{
hdfsFileInfo* fileinfo;
fileinfo = hdfsGetPathInfo(m_fs,pathname);
bool retval = (fileinfo ? fileinfo->mKind == kObjectKindDirectory : false);
if( fileinfo )
hdfsFreeFileInfo(fileinfo,1);
return retval;
hdfsFileInfo* fileinfo;
fileinfo = hdfsGetPathInfo(m_fs, pathname);
bool retval = (fileinfo ? fileinfo->mKind == kObjectKindDirectory : false);
if ( fileinfo )
hdfsFreeFileInfo(fileinfo, 1);
return retval;
}
int HdfsFileSystem::copyFile(const char* srcPath, const char* destPath) const
{
int ret = hdfsCopy(m_fs, srcPath, m_fs, destPath);
int ret = hdfsCopy(m_fs, srcPath, m_fs, destPath);
int n = 0; // retry count
while (ret != 0 && n++ < 25)
{
if (n < 10)
usleep(10000);
else
usleep(200000);
int n = 0; // retry count
if( IDBLogger::isEnabled() )
IDBLogger::logFSop2( HDFS, "copyFile-retry", srcPath, destPath, this, ret);
while (ret != 0 && n++ < 25)
{
if (n < 10)
usleep(10000);
else
usleep(200000);
ret = hdfsCopy(m_fs, srcPath, m_fs, destPath);
}
if ( IDBLogger::isEnabled() )
IDBLogger::logFSop2( HDFS, "copyFile-retry", srcPath, destPath, this, ret);
if( IDBLogger::isEnabled() )
IDBLogger::logFSop2( HDFS, "copyFile", srcPath, destPath, this, ret);
ret = hdfsCopy(m_fs, srcPath, m_fs, destPath);
}
return ret;
if ( IDBLogger::isEnabled() )
IDBLogger::logFSop2( HDFS, "copyFile", srcPath, destPath, this, ret);
return ret;
}
bool HdfsFileSystem::filesystemIsUp() const
{
return (m_fs != NULL);
return (m_fs != NULL);
}
}