Files
mongo/db/dur_writetodatafiles.cpp

100 lines
3.9 KiB
C++
Raw Normal View History

2011-01-04 00:40:41 -05:00
// @file dur_writetodatafiles.cpp apply the writes back to the non-private MMF after they are for certain in redo log
2010-12-17 11:52:42 -05:00
/**
* Copyright (C) 2009 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pch.h"
#include "dur_commitjob.h"
2010-12-17 12:13:50 -05:00
#include "dur_stats.h"
2010-12-26 11:17:07 -05:00
#include "dur_recover.h"
2010-12-26 11:50:37 -05:00
#include "../util/timer.h"
2010-12-17 11:52:42 -05:00
2011-01-04 00:40:41 -05:00
namespace mongo {
2010-12-17 11:52:42 -05:00
namespace dur {
void debugValidateAllMapsMatch();
2010-12-17 11:52:42 -05:00
2011-01-04 00:40:41 -05:00
/** apply the writes back to the non-private MMF after they are for certain in redo log
2010-12-17 11:52:42 -05:00
(1) todo we don't need to write back everything every group commit. we MUST write back
2011-01-04 00:40:41 -05:00
that which is going to be a remapped on its private view - but that might not be all
2010-12-17 11:52:42 -05:00
views.
(2) todo should we do this using N threads? would be quite easy
see Hackenberg paper table 5 and 6. 2 threads might be a good balance.
2011-01-04 00:40:41 -05:00
(3) with enough work, we could do this outside the read lock. it's a bit tricky though.
- we couldn't do it from the private views then as they may be changing. would have to then
2010-12-17 11:52:42 -05:00
be from the journal alignedbuffer.
2011-01-04 00:40:41 -05:00
- we need to be careful the file isn't unmapped on us -- perhaps a mutex or something
2010-12-17 11:52:42 -05:00
with MongoMMF on closes or something to coordinate that.
locking: in read lock when called
@see https://docs.google.com/drawings/edit?id=1TklsmZzm7ohIZkwgeK6rMvsdaR13KjtJYMsfLr175Zc&hl=en
*/
2010-12-26 11:17:07 -05:00
void WRITETODATAFILES_Impl1() {
RecoveryJob::get().processSection(commitJob._ab.buf(), commitJob._ab.len());
2010-12-26 11:17:07 -05:00
}
// the old implementation
2011-01-04 00:40:41 -05:00
void WRITETODATAFILES_Impl2() {
2010-12-17 11:52:42 -05:00
/* we go backwards as what is at the end is most likely in the cpu cache. it won't be much, but we'll take it. */
2011-01-04 00:40:41 -05:00
for( set<WriteIntent>::const_iterator it(commitJob.writes().begin()), end(commitJob.writes().end()); it != end; ++it ) {
const WriteIntent& intent = *it;
2010-12-27 11:29:16 -05:00
stats.curr->_writeToDataFilesBytes += intent.length();
dassert(intent.w_ptr);
memcpy(intent.w_ptr, intent.start(), intent.length());
2010-12-17 11:52:42 -05:00
}
2010-12-26 11:17:07 -05:00
}
2010-12-26 14:01:19 -05:00
#if defined(_EXPERIMENTAL)
2011-01-04 00:40:41 -05:00
void WRITETODATAFILES_Impl3() {
2010-12-26 14:01:19 -05:00
/* we go backwards as what is at the end is most likely in the cpu cache. it won't be much, but we'll take it. */
2011-01-04 00:40:41 -05:00
for( set<WriteIntent>::const_iterator it(commitJob.writes().begin()), end(commitJob.writes().end()); it != end; ++it ) {
2010-12-26 14:01:19 -05:00
const WriteIntent& intent = *it;
2010-12-30 14:12:29 -05:00
stats.curr->_writeToDataFilesBytes += intent.length();
2010-12-26 14:01:19 -05:00
dassert(intent.w_ptr);
2011-01-04 00:40:41 -05:00
memcpy(intent.w_ptr,
commitJob._ab.atOfs(intent.ofsInJournalBuffer),
intent.length());
2010-12-26 14:01:19 -05:00
}
}
#endif
2011-01-04 00:40:41 -05:00
void WRITETODATAFILES() {
2010-12-30 08:32:51 -05:00
dbMutex.assertAtLeastReadLocked();
2011-01-05 15:40:43 -05:00
MongoFile::markAllWritable(); // for _DEBUG. normally we don't write in a read lock
2010-12-26 11:50:37 -05:00
Timer t;
2010-12-26 14:01:19 -05:00
#if defined(_EXPERIMENTAL)
WRITETODATAFILES_Impl3();
#else
2010-12-26 11:17:07 -05:00
WRITETODATAFILES_Impl1();
2010-12-26 14:01:19 -05:00
#endif
2010-12-27 11:29:16 -05:00
stats.curr->_writeToDataFilesMicros += t.micros();
2011-01-05 15:40:43 -05:00
if (!dbMutex.isWriteLocked())
MongoFile::unmarkAllWritable();
debugValidateAllMapsMatch();
2010-12-17 11:52:42 -05:00
}
}
}