[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/nepomuk-kde/backupsync/service
From: Vishesh Handa <handa.vish () gmail ! com>
Date: 2010-07-31 21:23:50
Message-ID: 20100731212350.7E99CAC783 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1157692 by vhanda:
* Added methods to lock/unlock the LogStorage
* Time stamps are NOT in UTC ( easier to Debug )
* Fixed single cardinality merging. ( It works perfectly! )
M +1 -0 backupstorage.cpp
M +2 -2 diffgenerator.cpp
M +19 -1 logstorage.cpp
M +22 -0 logstorage.h
M +30 -6 syncrequest.cpp
M +1 -1 syncrequest_p.h
--- trunk/playground/base/nepomuk-kde/backupsync/service/backupstorage.cpp \
#1157691:1157692 @@ -97,6 +97,7 @@
void Nepomuk::BackupStorage::create()
{
+ //FIXME: The time stamps should be changed to UTC if UTC time is being used.
add( Sync::ChangeLog( getBackupStatements() ) );
}
--- trunk/playground/base/nepomuk-kde/backupsync/service/diffgenerator.cpp \
#1157691:1157692 @@ -103,14 +103,14 @@
void Nepomuk::DiffGenerator::statementAdded(const Soprano::Statement & st)
{
QMutexLocker locker( &m_queueMutex );
- m_recordQueue.enqueue( Sync::ChangeLogRecord( \
QDateTime::currentDateTime().toUTC(), true, st ) ); + m_recordQueue.enqueue( \
Sync::ChangeLogRecord( QDateTime::currentDateTime()/*.toUTC()*/, true, st ) ); \
m_queueWaiter.wakeAll(); }
void Nepomuk::DiffGenerator::statementRemoved(const Soprano::Statement & st)
{
QMutexLocker locker( &m_queueMutex );
- m_recordQueue.enqueue( Sync::ChangeLogRecord( \
QDateTime::currentDateTime().toUTC(), false, st ) ); + m_recordQueue.enqueue( \
Sync::ChangeLogRecord( QDateTime::currentDateTime()/*.toUTC()*/, false, st ) ); \
m_queueWaiter.wakeAll(); }
--- trunk/playground/base/nepomuk-kde/backupsync/service/logstorage.cpp \
#1157691:1157692 @@ -30,6 +30,7 @@
Nepomuk::LogStorage::LogStorage()
{
m_dirUrl = KStandardDirs::locateLocal( "data", "nepomuk/backupsync/log/" );
+ m_locked = false;
}
@@ -68,8 +69,10 @@
QDir dir( m_dirUrl );
const QStringList& entries = dir.entryList( QDir::Files, QDir::Name );
- if( entries.empty() )
+ if( entries.empty() ) {
+ kDebug() << "No enteries to generate a ChangeLog from";
return Sync::ChangeLog();
+ }
foreach( const QString & fileName, entries ) {
QDateTime dt = QDateTime::fromString( fileName, Qt::ISODate );
@@ -80,6 +83,10 @@
log << Sync::ChangeLog::create( m_dirUrl + fileName, min );
}
+ //TODO: Optimize this!
+ if( m_locked )
+ log.removeRecordsGreaterThan( m_lockTime );
+
return log;
}
@@ -185,3 +192,14 @@
}
+void Nepomuk::LogStorage::lock()
+{
+ m_locked = true;
+ m_lockTime = QDateTime::currentDateTime();
+}
+
+void Nepomuk::LogStorage::unlock()
+{
+ m_locked = false;
+}
+
--- trunk/playground/base/nepomuk-kde/backupsync/service/logstorage.h \
#1157691:1157692 @@ -44,6 +44,25 @@
void addRecord( const Sync::ChangeLogRecord & record );
void removeRecords( const QDateTime & lessThan );
+ /**
+ * Locks the LogStorage at the currentDateTime. All calls to getChangeLog \
will + * not returns any ChangeLogRecords whose time stamp >= currentTime.
+ * The will last untill the LogStorage is unlocked.
+ *
+ * Locks are not recursive. Only the last called lock is valid.
+ *
+ * The logs are still saved. The only change is that getChangeLog will not \
return + * them to you.
+ *
+ * \sa unlock getChangeLog
+ */
+ void lock();
+
+ /**
+ * Unlocks the LogStorage. Now all the records will be returned.
+ */
+ void unlock();
+
private:
friend class Nepomuk::LogStorageHelper;
@@ -55,6 +74,9 @@
static const int m_maxFileRecords = 250;
QString m_dirUrl;
+
+ bool m_locked;
+ QDateTime m_lockTime;
};
}
--- trunk/playground/base/nepomuk-kde/backupsync/service/syncrequest.cpp \
#1157691:1157692 @@ -157,7 +157,9 @@
//
// Get own changeLog
//
+ kDebug() << "minDateTime : " << d->m_minDateTime;
Sync::ChangeLog ownLog = LogStorage::instance()->getChangeLog( d->m_minDateTime \
); + kDebug() << "own Log : " << ownLog.size();
// Get our and their hash
// ownHash = current local hash from system's logfile
@@ -211,6 +213,8 @@
d->resolveMultipleCardinality( rs, theirRecords, ownRecords );
}
}
+
+ if( !rs.propHash.isEmpty() )
d->m_jobs.append( rs );
}
theirHash.clear();
@@ -246,10 +250,12 @@
kDebug() << (nodes.size() == 1 ? "SINGLE" : "MULTIPLE");
st.setContext( d->m_graphWrapper.currentGraph() );
foreach( const Soprano::Node & n, nodes ) {
+ if( n.isValid() ) {
kDebug() << "Adding : "<< n;
st.setObject( n );
d->m_model->addStatement( st );
}
+ }
if( nodes.size() != 1 ) {
emit multipleMerge( res.uri.toString(), propUri.toString() );
}
@@ -276,27 +282,44 @@
}
}
-
+/* Changes the rs to reflect how the new state of the resource should be
+ */
void Nepomuk::SyncRequest::Private::resolveSingleCardinality(Nepomuk::Sync::SimpleResource& \
rs, const QList< Nepomuk::Sync::ChangeLogRecord >& theirRecords, const QList< \
Nepomuk::Sync::ChangeLogRecord >& ownRecords) {
kDebug() << "O: " << ownRecords.size() << " " << "T:" << theirRecords.size();
- const QUrl & propUri = theirRecords.first().st().predicate().uri();
//kDebug() << propUri;
+ /*
if( ownRecords.empty() ) {
const Sync::ChangeLogRecord & record = maxRecord( theirRecords );
+ if( record.added() ) {
+ kDebug() << "Resolved - Adding " << record.st().object();
rs.propHash.insert( propUri, record.st().object() );
+ }
+ else {
+ kDebug() << "Resolved - Removing";
+ rs.propHash.insert( propUri, Soprano::Node() );
+ }
return;
- }
+ }*/
//Find max on the basis of time stamp
Sync::ChangeLogRecord theirMax = maxRecord( theirRecords );
Sync::ChangeLogRecord ownMax = maxRecord( ownRecords );
- Sync::ChangeLogRecord max = ownMax > theirMax ? ownMax : theirMax;
+ kDebug() << "TheirMax : "<< theirMax.toString();
+ kDebug() << "OwnMax " << ownMax.toString();
- if( max.added() ) {
- rs.propHash.insert( propUri, max.st().object() );
+ if( theirMax > ownMax ) {
+ const QUrl & propUri = theirMax.st().predicate().uri();
+
+ if( theirMax.added() ) {
+ kDebug() << "Resolved - Adding " << theirMax.st().object();
+ rs.propHash.insert( propUri, theirMax.st().object() );
+ } else {
+ kDebug() << "Resolved - Removing";
+ rs.propHash.insert( propUri, Soprano::Node() );
}
+ }
//kDebug() << rs.propHash.values( propUri ).size();
}
/*
@@ -325,6 +348,7 @@
}*/
+//FIXME: Buggy!
void Nepomuk::SyncRequest::Private::resolveMultipleCardinality(Nepomuk::Sync::SimpleResource& \
rs, const QList< Nepomuk::Sync::ChangeLogRecord >& theirRecords, const QList< \
Nepomuk::Sync::ChangeLogRecord >& ownRecords) {
kDebug() << "O: " << ownRecords.size() << " " << "T:" << theirRecords.size();
--- trunk/playground/base/nepomuk-kde/backupsync/service/syncrequest_p.h \
#1157691:1157692 @@ -72,7 +72,7 @@
/**
* Same as multiple Cardinality resolution, but a lot faster. It figures out \
which statement
- * should be present by look at the max time stamp.
+ * should be present by looking at the max time stamp.
*/
void resolveSingleCardinality( Sync::SimpleResource & rs, const \
QList<Sync::ChangeLogRecord> & theirRecords, const QList<Sync::ChangeLogRecord> & \
ownRecords );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic