summaryrefslogtreecommitdiff
path: root/db/dur_recover.h
blob: dd8447b6ee0075e76b85cf86ecfe3d43edb6ca83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// @file dur.h durability support

#pragma once

#include "../util/concurrency/mutex.h"
#include "../util/file.h"

namespace mongo {
    class MemoryMappedFile;

    namespace dur {
        struct ParsedJournalEntry;

        /** call go() to execute a recovery from existing journal files.
         */
        class RecoveryJob : boost::noncopyable {
        public:
            RecoveryJob() :_lastDataSyncedFromLastRun(0), _mx("recovery") {}
            void go(vector<path>& files);
            ~RecoveryJob();
            void processSection(const void *, unsigned len, bool doDurOps);
            void close(); // locks and calls _close()

            static RecoveryJob & get() { return _instance; }
        private:
            void applyEntry(const ParsedJournalEntry& entry, bool apply, bool dump);
            void applyEntries(const vector<ParsedJournalEntry> &entries);
            bool processFileBuffer(const void *, unsigned len);
            bool processFile(path journalfile);
            void _close(); // doesn't lock

            /** retrieve the File for the specified dbName plus file number.
                open if not yet open.
                @param fileNo a value of -1 indicates ".ns"
                @param ofs offset to add to the pointer before returning
            */
            File& getFile(const char *dbName, int fileNo);

            // fileno,dbname -> File
            // all close at end (destruction) of RecoveryJob
            typedef map< pair<int,string>, File > FileMap;
            FileMap _files;

            unsigned long long _lastDataSyncedFromLastRun;

            mongo::mutex _mx; // protects _files

            static RecoveryJob _instance;
        };
    }
}