persistentstorage/sql/SRC/Server/Compact/SqlCompact.cpp
branchRCL_3
changeset 23 26645d81f48d
parent 9 667e88a979d7
child 24 cc28652e0254
equal deleted inserted replaced
21:28839de615b4 23:26645d81f48d
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include "SqlPanic.h"
    16 #include "SqlAssert.h"
    17 #include "SqlCompact.h"
    17 #include "SqlCompact.h"
    18 #include "SqlCompactEntry.h"
    18 #include "SqlCompactEntry.h"
    19 #include "SqlCompactTimer.h"
    19 #include "SqlCompactTimer.h"
    20 #include "SqlUtil.h"
    20 #include "SqlUtil.h"
       
    21 #include "OstTraceDefinitions.h"
       
    22 #ifdef OST_TRACE_COMPILER_IN_USE
       
    23 #include "SqlCompactTraces.h"
       
    24 #endif
       
    25 #include "SqlTraceDef.h"
    21 
    26 
    22 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    27 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    23 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    28 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    24 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    29 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    25 
    30 
    36 /**
    41 /**
    37 CSqlCompactSettings invariant.
    42 CSqlCompactSettings invariant.
    38 */
    43 */
    39 void TSqlCompactSettings::Invariant() const
    44 void TSqlCompactSettings::Invariant() const
    40 	{
    45 	{
    41 	__SQLASSERT(iStepLength > 0, ESqlPanicInternalError);
    46 	__ASSERT_DEBUG(iStepLength > 0, __SQLPANIC(ESqlPanicInternalError));
    42 	__SQLASSERT(iFreePageThresholdKb >= 0, ESqlPanicInternalError);
    47 	__ASSERT_DEBUG(iFreePageThresholdKb >= 0, __SQLPANIC(ESqlPanicInternalError));
    43 	}
    48 	}
    44 #endif//_DEBUG
    49 #endif//_DEBUG
    45 
    50 
    46 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    51 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    47 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    52 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    70 @panic SqlDb 4 In _DEBUG mode. NULL aConnFactoryL.
    75 @panic SqlDb 4 In _DEBUG mode. NULL aConnFactoryL.
    71 @panic SqlDb 4 In _DEBUG mode. Zero or negative aCompactStepInterval.
    76 @panic SqlDb 4 In _DEBUG mode. Zero or negative aCompactStepInterval.
    72 */
    77 */
    73 CSqlCompactor* CSqlCompactor::NewL(TSqlCompactConnFactoryL aConnFactoryL, TInt aCompactStepInterval)
    78 CSqlCompactor* CSqlCompactor::NewL(TSqlCompactConnFactoryL aConnFactoryL, TInt aCompactStepInterval)
    74 	{
    79 	{
    75 	__SQLASSERT(aConnFactoryL != NULL, ESqlPanicBadArgument);
    80 	__ASSERT_DEBUG(aConnFactoryL != NULL, __SQLPANIC2(ESqlPanicBadArgument));
    76 	__SQLASSERT(aCompactStepInterval > 0, ESqlPanicBadArgument);
    81 	__ASSERT_DEBUG(aCompactStepInterval > 0, __SQLPANIC2(ESqlPanicBadArgument));
    77 	CSqlCompactor* self = new (ELeave) CSqlCompactor(aConnFactoryL);
    82 	CSqlCompactor* self = new (ELeave) CSqlCompactor(aConnFactoryL);
    78 	CleanupStack::PushL(self);
    83 	CleanupStack::PushL(self);
    79 	self->ConstructL(aCompactStepInterval);
    84 	self->ConstructL(aCompactStepInterval);
    80 	CleanupStack::Pop(self);
    85 	CleanupStack::Pop(self);
    81 	return self;
    86 	return self;
    87 */
    92 */
    88 CSqlCompactor::~CSqlCompactor()
    93 CSqlCompactor::~CSqlCompactor()
    89 	{
    94 	{
    90 	for(TInt idx=iEntries.Count()-1;idx>=0;--idx)
    95 	for(TInt idx=iEntries.Count()-1;idx>=0;--idx)
    91 		{
    96 		{
    92 		__SQLASSERT(iEntries[idx] != NULL, ESqlPanicInternalError);
    97 		__ASSERT_DEBUG(iEntries[idx] != NULL, __SQLPANIC(ESqlPanicInternalError));
    93 		while(iEntries[idx]->Release() != 0)
    98 		while(iEntries[idx]->Release() != 0)
    94 			{
    99 			{
    95 			}
   100 			}
    96 		}
   101 		}
    97 	iEntries.Close();
   102 	iEntries.Close();
   132 @panic SqlDb 4 In _DEBUG mode. Too short or too long database name (aFullName parameter)
   137 @panic SqlDb 4 In _DEBUG mode. Too short or too long database name (aFullName parameter)
   133 @panic SqlDb 7 In _DEBUG mode. An entry with the specified name has been found but the entry is NULL.
   138 @panic SqlDb 7 In _DEBUG mode. An entry with the specified name has been found but the entry is NULL.
   134 */
   139 */
   135 void CSqlCompactor::AddEntryL(const TDesC& aFullName, const TSqlCompactSettings& aSettings)
   140 void CSqlCompactor::AddEntryL(const TDesC& aFullName, const TSqlCompactSettings& aSettings)
   136 	{
   141 	{
   137 	__SQLASSERT(aFullName.Length() > 0 && aFullName.Length() <= KMaxFileName, ESqlPanicBadArgument);
   142 	__ASSERT_DEBUG(aFullName.Length() > 0 && aFullName.Length() <= KMaxFileName, __SQLPANIC(ESqlPanicBadArgument));
   138 	SQLCOMPACTOR_INVARIANT();
   143 	SQLCOMPACTOR_INVARIANT();
   139 	CSqlCompactEntry* entry = NULL;
   144 	CSqlCompactEntry* entry = NULL;
   140 	TInt idx = iEntries.FindInOrder(aFullName, &CSqlCompactor::Search);
   145 	TInt idx = iEntries.FindInOrder(aFullName, &CSqlCompactor::Search);
   141 	if(idx == KErrNotFound)
   146 	if(idx == KErrNotFound)
   142 		{
   147 		{
       
   148 		SQL_TRACE_COMPACT(OstTraceExt4(TRACE_INTERNALS, CSQLCOMPACTOR_ADDENTRYL1, "0x%X;CSqlCompactor::AddEntryL;New entry;aFullName=%S;iStepLength=%d;iFreePageThreashold=%d", (TUint)this, __SQLPRNSTR(aFullName), aSettings.iStepLength, aSettings.iFreePageThresholdKb));
   143 		entry = CSqlCompactEntry::NewLC(aFullName, iConnFactoryL, aSettings, *iTimer);
   149 		entry = CSqlCompactEntry::NewLC(aFullName, iConnFactoryL, aSettings, *iTimer);
   144 		TLinearOrder<CSqlCompactEntry> order(&CSqlCompactor::Compare);
   150 		TLinearOrder<CSqlCompactEntry> order(&CSqlCompactor::Compare);
   145 		__SQLLEAVE_IF_ERROR(iEntries.InsertInOrder(entry, order));
   151 		__SQLLEAVE_IF_ERROR(iEntries.InsertInOrder(entry, order));
   146 		CleanupStack::Pop(entry);
   152 		CleanupStack::Pop(entry);
   147 		}
   153 		}
   148 	else
   154 	else
   149 		{
   155 		{
       
   156 		SQL_TRACE_COMPACT(OstTraceExt4(TRACE_INTERNALS, CSQLCOMPACTOR_ADDENTRYL2, "0x%X;CSqlCompactor::AddEntryL;Reuse entry;aFullName=%S;iStepLength=%d;iFreePageThreashold=%d", (TUint)this, __SQLPRNSTR(aFullName), aSettings.iStepLength, aSettings.iFreePageThresholdKb));
   150 		entry = iEntries[idx];
   157 		entry = iEntries[idx];
   151 		__SQLASSERT(entry != NULL, ESqlPanicInternalError);
   158 		__ASSERT_DEBUG(entry != NULL, __SQLPANIC(ESqlPanicInternalError));
   152 		(void)entry->AddRef();
   159 		(void)entry->AddRef();
   153 		}
   160 		}
   154 	SQLCOMPACTOR_INVARIANT();
   161 	SQLCOMPACTOR_INVARIANT();
   155 	}
   162 	}
   156 
   163 
   161 
   168 
   162 @param aFullName The full database name, including the path.
   169 @param aFullName The full database name, including the path.
   163 */
   170 */
   164 void CSqlCompactor::ReleaseEntry(const TDesC& aFullName)
   171 void CSqlCompactor::ReleaseEntry(const TDesC& aFullName)
   165 	{
   172 	{
       
   173 	SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTOR_RELEASEENTRY1, "0x%X;CSqlCompactor::ReleaseEntry;aFullName=%S", (TUint)this, __SQLPRNSTR(aFullName)));
   166 	SQLCOMPACTOR_INVARIANT();
   174 	SQLCOMPACTOR_INVARIANT();
   167 	TInt idx = iEntries.FindInOrder(aFullName, &CSqlCompactor::Search);
   175 	TInt idx = iEntries.FindInOrder(aFullName, &CSqlCompactor::Search);
   168 	__SQLASSERT(idx >= 0, ESqlPanicInternalError);
   176 	__ASSERT_DEBUG(idx >= 0, __SQLPANIC(ESqlPanicInternalError));
   169 	if(idx >= 0)
   177 	if(idx >= 0)
   170 		{
   178 		{
   171 		CSqlCompactEntry* entry = iEntries[idx];
   179 		CSqlCompactEntry* entry = iEntries[idx];
   172 		__SQLASSERT(entry != NULL, ESqlPanicInternalError);
   180 		__ASSERT_DEBUG(entry != NULL, __SQLPANIC(ESqlPanicInternalError));
   173 		if(entry)
   181 		if(entry)
   174 			{
   182 			{
   175 			if(entry->Release() == 0)
   183 			if(entry->Release() == 0)
   176 				{
   184 				{
   177 				iEntries.Remove(idx);			
   185 				iEntries.Remove(idx);			
   197 */
   205 */
   198 CSqlCompactor::CSqlCompactor(TSqlCompactConnFactoryL aConnFactoryL) :
   206 CSqlCompactor::CSqlCompactor(TSqlCompactConnFactoryL aConnFactoryL) :
   199 	iConnFactoryL(aConnFactoryL),
   207 	iConnFactoryL(aConnFactoryL),
   200 	iEntries(KEntriesGranularity)
   208 	iEntries(KEntriesGranularity)
   201 	{
   209 	{
   202 	__SQLASSERT(aConnFactoryL != NULL, ESqlPanicBadArgument);
   210 	__ASSERT_DEBUG(aConnFactoryL != NULL, __SQLPANIC(ESqlPanicBadArgument));
   203 	}
   211 	}
   204 
   212 
   205 /**
   213 /**
   206 Initializes the created CSqlCompactor instance.
   214 Initializes the created CSqlCompactor instance.
   207 
   215 
   209 
   217 
   210 @panic SqlDb 4 In _DEBUG mode. Zero or negative aCompactStepInterval.
   218 @panic SqlDb 4 In _DEBUG mode. Zero or negative aCompactStepInterval.
   211 */
   219 */
   212 void CSqlCompactor::ConstructL(TInt aCompactStepInterval)
   220 void CSqlCompactor::ConstructL(TInt aCompactStepInterval)
   213 	{
   221 	{
   214 	__SQLASSERT(aCompactStepInterval > 0, ESqlPanicBadArgument);
   222 	__ASSERT_DEBUG(aCompactStepInterval > 0, __SQLPANIC(ESqlPanicBadArgument));
   215 	iTimer = CSqlCompactTimer::NewL(aCompactStepInterval);
   223 	iTimer = CSqlCompactTimer::NewL(aCompactStepInterval);
   216 	}
   224 	}
   217 
   225 
   218 /**
   226 /**
   219 Static method used internally for performing a search in the container using database name as a key.
   227 Static method used internally for performing a search in the container using database name as a key.
   221 @param aFullName The full database name, including the path.
   229 @param aFullName The full database name, including the path.
   222 @param aEntry CSqlCompactor reference.
   230 @param aEntry CSqlCompactor reference.
   223 */
   231 */
   224 /* static */TInt CSqlCompactor::Search(const TDesC* aFullName, const CSqlCompactEntry& aEntry)
   232 /* static */TInt CSqlCompactor::Search(const TDesC* aFullName, const CSqlCompactEntry& aEntry)
   225 	{
   233 	{
   226 	__SQLASSERT(&aEntry != NULL, ESqlPanicInternalError);
   234 	__ASSERT_DEBUG(&aEntry != NULL, __SQLPANIC2(ESqlPanicInternalError));
   227 	__SQLASSERT(aFullName != NULL, ESqlPanicInternalError);
   235 	__ASSERT_DEBUG(aFullName != NULL, __SQLPANIC2(ESqlPanicInternalError));
   228 	const TDesC& fullName = *aFullName;
   236 	const TDesC& fullName = *aFullName;
   229 	__SQLASSERT(fullName.Length() > 0 && fullName.Length() <= KMaxFileName, ESqlPanicInternalError);
   237 	__ASSERT_DEBUG(fullName.Length() > 0 && fullName.Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicInternalError));
   230 	__SQLASSERT(aEntry.FullName().Length() > 0 && aEntry.FullName().Length() <= KMaxFileName, ESqlPanicInternalError);
   238 	__ASSERT_DEBUG(aEntry.FullName().Length() > 0 && aEntry.FullName().Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicInternalError));
   231 	return fullName.CompareF(aEntry.FullName());
   239 	return fullName.CompareF(aEntry.FullName());
   232 	}
   240 	}
   233 
   241 
   234 /**
   242 /**
   235 Static method used internally for performing a search in the container using a CSqlCompactEntry reference as a key.
   243 Static method used internally for performing a search in the container using a CSqlCompactEntry reference as a key.
   236 */
   244 */
   237 /* static */TInt CSqlCompactor::Compare(const CSqlCompactEntry& aLeft, const CSqlCompactEntry& aRight)
   245 /* static */TInt CSqlCompactor::Compare(const CSqlCompactEntry& aLeft, const CSqlCompactEntry& aRight)
   238 	{
   246 	{
   239 	__SQLASSERT(&aLeft != NULL, ESqlPanicInternalError);
   247 	__ASSERT_DEBUG(&aLeft != NULL, __SQLPANIC2(ESqlPanicInternalError));
   240 	__SQLASSERT(&aRight != NULL, ESqlPanicInternalError);
   248 	__ASSERT_DEBUG(&aRight != NULL, __SQLPANIC2(ESqlPanicInternalError));
   241 	__SQLASSERT(aLeft.FullName().Length() > 0 && aLeft.FullName().Length() <= KMaxFileName, ESqlPanicInternalError);
   249 	__ASSERT_DEBUG(aLeft.FullName().Length() > 0 && aLeft.FullName().Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicInternalError));
   242 	__SQLASSERT(aRight.FullName().Length() > 0 && aRight.FullName().Length() <= KMaxFileName, ESqlPanicInternalError);
   250 	__ASSERT_DEBUG(aRight.FullName().Length() > 0 && aRight.FullName().Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicInternalError));
   243 	return aLeft.FullName().CompareF(aRight.FullName());
   251 	return aLeft.FullName().CompareF(aRight.FullName());
   244 	}
   252 	}
   245 
   253 
   246 #ifdef _DEBUG
   254 #ifdef _DEBUG
   247 /**
   255 /**
   248 CSqlCompactor invariant.
   256 CSqlCompactor invariant.
   249 */
   257 */
   250 void CSqlCompactor::Invariant() const
   258 void CSqlCompactor::Invariant() const
   251 	{
   259 	{
   252 	__SQLASSERT(iConnFactoryL != NULL, ESqlPanicInternalError);
   260 	__ASSERT_DEBUG(iConnFactoryL != NULL, __SQLPANIC(ESqlPanicInternalError));
   253 	__SQLASSERT(iTimer != NULL, ESqlPanicInternalError);
   261 	__ASSERT_DEBUG(iTimer != NULL, __SQLPANIC(ESqlPanicInternalError));
   254 	iTimer->Invariant();
   262 	iTimer->Invariant();
   255 	for(TInt idx=iEntries.Count()-1;idx>=0;--idx)
   263 	for(TInt idx=iEntries.Count()-1;idx>=0;--idx)
   256 		{
   264 		{
   257 		__SQLASSERT(iEntries[idx] != NULL, ESqlPanicInternalError);
   265 		__ASSERT_DEBUG(iEntries[idx] != NULL, __SQLPANIC(ESqlPanicInternalError));
   258 		iEntries[idx]->Invariant();
   266 		iEntries[idx]->Invariant();
   259 		}
   267 		}
   260 	}
   268 	}
   261 #endif//_DEBUG
   269 #endif//_DEBUG