~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/falcon/SectorBuffer.cpp

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2008 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <memory.h>
 
17
#include "Engine.h"
 
18
#include "SectorBuffer.h"
 
19
#include "SectorCache.h"
 
20
#include "BDB.h"
 
21
#include "Dbb.h"
 
22
#include "Page.h"
 
23
 
 
24
SectorBuffer::SectorBuffer()
 
25
{
 
26
        activeLength = 0;
 
27
        sectorNumber = -1;
 
28
}
 
29
 
 
30
SectorBuffer::~SectorBuffer(void)
 
31
{
 
32
}
 
33
 
 
34
void SectorBuffer::readPage(Bdb* bdb)
 
35
{
 
36
        int pageSize  = cache->pageSize;
 
37
 
 
38
        int offset = (bdb->pageNumber % cache->pagesPerSector) * pageSize;
 
39
        ASSERT(offset < activeLength);
 
40
        
 
41
        Page *page = (Page *)(buffer + offset);
 
42
 
 
43
        /*
 
44
        Validate page checksum.
 
45
        Do it only once and after that reset the checksum field. It is necessary
 
46
        because later the checksum in header might be incorrect (when page is read,
 
47
        modified and written back to buffer�but not yet to disk).Also, the same page
 
48
        might be read multiple times and we want to avoid the checksum calculation
 
49
        overhead.
 
50
        */
 
51
        if(page->checksum != NO_CHECKSUM_MAGIC)
 
52
                {
 
53
                dbb->validateChecksum(page, pageSize, ((int64)bdb->pageNumber) * pageSize);
 
54
                page->checksum = NO_CHECKSUM_MAGIC;
 
55
                }
 
56
        memcpy(bdb->buffer, page, pageSize);
 
57
}
 
58
 
 
59
void SectorBuffer::readSector()
 
60
{
 
61
        uint64 offset = (uint64)sectorNumber * (uint64)cache->pagesPerSector * (uint64)cache->pageSize;
 
62
        activeLength = dbb->pread(offset, SECTOR_BUFFER_SIZE, buffer);
 
63
}
 
64
 
 
65
void SectorBuffer::setSector(Dbb* db, int sector)
 
66
{
 
67
        dbb = db;
 
68
        sectorNumber = sector;
 
69
}
 
70
 
 
71
void SectorBuffer::writePage(Bdb* bdb)
 
72
{
 
73
        int offset = (bdb->pageNumber % cache->pagesPerSector) * cache->pageSize;
 
74
        memcpy(buffer + offset, bdb->buffer, cache->pageSize);
 
75
        offset += cache->pageSize;
 
76
        activeLength = MAX(activeLength, offset);
 
77
}