~akiban-technologies/akiban-persistit/build

« back to all changes in this revision

Viewing changes to src/main/java/com/persistit/VolumeStorageL2.java

merge pbeaman: Fixes bug1126868.

https://code.launchpad.net/~pbeaman/akiban-persistit/fix-1126868-lock-table-pruning/+merge/152063

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright © 2011-2012 Akiban Technologies, Inc.  All rights reserved.
 
3
 * 
 
4
 * This program and the accompanying materials are made available
 
5
 * under the terms of the Eclipse Public License v1.0 which
 
6
 * accompanies this distribution, and is available at
 
7
 * http://www.eclipse.org/legal/epl-v10.html
 
8
 * 
 
9
 * This program may also be available under different license terms.
 
10
 * For more information, see www.akiban.com or contact licensing@akiban.com.
 
11
 * 
 
12
 * Contributors:
 
13
 * Akiban Technologies, Inc.
 
14
 */
 
15
 
 
16
package com.persistit;
 
17
 
 
18
import java.io.File;
 
19
 
 
20
import com.persistit.exception.InUseException;
 
21
import com.persistit.exception.PersistitException;
 
22
 
 
23
/**
 
24
 * Manage all details of file I/O for a special <code>Volume</code> that backs
 
25
 * the {@link Exchange#lock()} method. The lock volume differs from a temporary
 
26
 * volume in the following ways:
 
27
 * <ul>
 
28
 * <li>It has a defined name and is visible in the
 
29
 * {@link Persistit#getVolumes()} array.</li>
 
30
 * <li>It is threadsafe.</li>
 
31
 * </ul>
 
32
 * Like a temporary volume, it is intended that pages of the lock volume should
 
33
 * seldom, if ever, need to be written to disk. And also like a temporary
 
34
 * volume, the contents of the lock volume are not recovered during startup.
 
35
 * 
 
36
 * @author peter
 
37
 */
 
38
class VolumeStorageL2 extends VolumeStorageT2 {
 
39
 
 
40
    final static String LOCK_VOLUME_FILE_PREFIX = "persistit_lockvol_";
 
41
    private Buffer _headBuffer;
 
42
 
 
43
    VolumeStorageL2(final Persistit persistit, final Volume volume, final File tempDirectory) {
 
44
        super(persistit, volume, tempDirectory);
 
45
    }
 
46
 
 
47
    /**
 
48
     * Indicate whether this is a temporary volume. The Lock volume is not
 
49
     * temporary, although it inherits most of the characteristics of a
 
50
     * temporary volume.
 
51
     * 
 
52
     * @return <code>true</code> if this volume is temporary
 
53
     */
 
54
    @Override
 
55
    boolean isTemp() {
 
56
        return false;
 
57
    }
 
58
 
 
59
    @Override
 
60
    void truncate() throws PersistitException {
 
61
        if (!claim(true, 0)) {
 
62
            throw new InUseException("Unable to acquire claim on " + this);
 
63
        }
 
64
        try {
 
65
            _headBuffer = _volume.getStructure().getPool().get(_volume, 0, true, false);
 
66
            _headBuffer.init(Buffer.PAGE_TYPE_HEAD);
 
67
            _headBuffer.setFixed();
 
68
 
 
69
            truncateInternal();
 
70
            releaseHeadBuffer();
 
71
 
 
72
        } finally {
 
73
            release();
 
74
        }
 
75
    }
 
76
 
 
77
    @Override
 
78
    void claimHeadBuffer() throws PersistitException {
 
79
        if (!_headBuffer.claim(true)) {
 
80
            throw new InUseException("Unable to acquire claim on " + _headBuffer);
 
81
        }
 
82
    }
 
83
 
 
84
    @Override
 
85
    void releaseHeadBuffer() {
 
86
        _headBuffer.release();
 
87
    }
 
88
 
 
89
}