hidden.py 5.03 KB
Newer Older
Aurel's avatar
Aurel committed
1 2
#
# Copyright (C) 2006-2009  Nexedi SA
Aurel's avatar
Aurel committed
3
#
Aurel's avatar
Aurel committed
4 5 6 7
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Aurel's avatar
Aurel committed
8
#
Aurel's avatar
Aurel committed
9 10 11 12 13 14 15 16 17
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

18
from neo import logging
Aurel's avatar
Aurel committed
19

20
from neo.storage.handlers import BaseMasterHandler
21 22
from neo.protocol import BROKEN_STATE, STORAGE_NODE_TYPE, DOWN_STATE, \
        TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE
23

24
class HiddenHandler(BaseMasterHandler):
Aurel's avatar
Aurel committed
25
    """This class implements a generic part of the event handlers."""
26

Aurel's avatar
Aurel committed
27 28
    def __init__(self, app):
        self.app = app
Grégory Wisniewski's avatar
Grégory Wisniewski committed
29
        BaseMasterHandler.__init__(self, app)
Aurel's avatar
Aurel committed
30 31 32 33 34

    def handleNotifyNodeInformation(self, conn, packet, node_list):
        """Store information on nodes, only if this is sent by a primary
        master node."""
        app = self.app
35
        self.app.nm.update(node_list)
36
        for node_type, addr, uuid, state in node_list:
Aurel's avatar
Aurel committed
37 38 39 40 41
            if node_type == STORAGE_NODE_TYPE:
                if uuid == self.app.uuid:
                    # This is me, do what the master tell me
                    if state in (DOWN_STATE, TEMPORARILY_DOWN_STATE, BROKEN_STATE):
                        conn.close()
42 43
                        erase_db = state == DOWN_STATE
                        self.app.shutdown(erase=erase_db)
44 45

    def handleRequestNodeIdentification(self, conn, packet, node_type,
46
                                        uuid, address, name):
47 48 49
        pass

    def handleAcceptNodeIdentification(self, conn, packet, node_type,
50
                   uuid, address, num_partitions, num_replicas, your_uuid):
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        pass

    def handleAnswerPrimaryMaster(self, conn, packet, primary_uuid,
                                  known_master_list):
        pass

    def handleAskLastIDs(self, conn, packet):
        pass

    def handleAskPartitionTable(self, conn, packet, offset_list):
        pass

    def handleSendPartitionTable(self, conn, packet, ptid, row_list):
        pass

    def handleNotifyPartitionChanges(self, conn, packet, ptid, cell_list):
67 68 69
        """This is very similar to Send Partition Table, except that
        the information is only about changes from the previous."""
        app = self.app
70
        if ptid <= app.pt.getID():
71
            # Ignore this packet.
72
            logging.debug('ignoring older partition changes')
73 74
            return

75 76 77 78 79
        # update partition table in memory and the database
        app.pt.update(ptid, cell_list, app.nm)
        app.dm.changePartitionTable(ptid, cell_list)

        # Check changes for replications
80
        for offset, uuid, state in cell_list:
Aurel's avatar
Aurel committed
81
            if uuid == app.uuid and app.replicator is not None:
82 83 84 85 86 87
                # If this is for myself, this can affect replications.
                if state == DISCARDED_STATE:
                    app.replicator.removePartition(offset)
                elif state == OUT_OF_DATE_STATE:
                    app.replicator.addPartition(offset)

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    def handleStartOperation(self, conn, packet):
        self.app.operational = True

    def handleStopOperation(self, conn, packet):
        pass

    def handleAskUnfinishedTransactions(self, conn, packet):
        pass

    def handleAskTransactionInformation(self, conn, packet, tid):
        pass

    def handleAskObjectPresent(self, conn, packet, oid, tid):
        pass

    def handleDeleteTransaction(self, conn, packet, tid):
        pass

    def handleCommitTransaction(self, conn, packet, tid):
        pass

    def handleLockInformation(self, conn, packet, tid):
        pass

    def handleUnlockInformation(self, conn, packet, tid):
        pass

    def handleAskObject(self, conn, packet, oid, serial, tid):
        pass

    def handleAskTIDs(self, conn, packet, first, last, partition):
        pass

    def handleAskObjectHistory(self, conn, packet, oid, first, last):
        pass

    def handleAskStoreTransaction(self, conn, packet, tid, user, desc,
                                  ext, oid_list):
        pass

    def handleAskStoreObject(self, conn, packet, oid, serial,
                             compression, checksum, data, tid):
        pass

    def handleAbortTransaction(self, conn, packet, tid):
133
        logging.debug('ignoring abort transaction')
134 135

    def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid):
136
        logging.debug('ignoring answer last ids')
137 138

    def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list):
139
        logging.debug('ignoring answer unfinished transactions')
140 141

    def handleAskOIDs(self, conn, packet, first, last, partition):
142
        logging.debug('ignoring ask oids')
143