Commit f96c2801 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Implemented the service handler. Added more utility methods. Made the master handler a bit safer.

git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@36 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent fb998338
......@@ -2,7 +2,8 @@ import logging
import MySQLdb
import os
from socket import inet_aton
from time import time
from time import time, gmtime
from struct import pack, unpack
from neo.config import ConfigurationManager
from neo.protocol import Packet, ProtocolError, \
......@@ -17,6 +18,7 @@ from neo.exception import ElectionFailure, PrimaryFailure, VerificationFailure,
from neo.master.election import ElectionEventHandler
from neo.master.recovery import RecoveryEventHandler
from neo.master.verification import VerificationEventHandler
from neo.master.service import ServiceEventHandler
from neo.pt import PartitionTable
class Application(object):
......@@ -414,7 +416,7 @@ class Application(object):
uuid_set = set()
# Determine to which nodes I should ask.
partition = tid % self.num_partitions
partition = self.getPartition(tid)
transaction_uuid_list = [cell.getUUID() for cell \
in self.pt.getCellList(partition, True)]
if len(transaction_uuid_list) == 0:
......@@ -450,7 +452,7 @@ class Application(object):
# Verify that all objects are present.
for oid in self.unfinished_oid_set:
self.asking_uuid_dict.clear()
partition = oid % self.num_partitions
partition = self.getPartition(oid)
object_uuid_list = [cell.getUUID() for cell \
in self.pt.getCellList(partition, True)]
if len(object_uuid_list) == 0:
......@@ -607,6 +609,9 @@ class Application(object):
em = self.em
nm = self.nm
# This dictionary is used to hold information on transactions being finished.
self.finishing_transaction_dict = {}
# Make sure that every connection has the service event handler.
for conn in em.getConnectionList():
conn.setHandler(handler)
......@@ -684,3 +689,32 @@ class Application(object):
self.lptid = ''.join(l)
return self.lptid
def getNextTID(self):
tm = time()
gmt = gmtime(tm)
upper = (((gmt.tm_year * 12 + gmt.tm_mon) * 31 + gmt.tm_mday - 1) \
* 24 + gmt.tm_hour) * 60 + gmt.tm_min
lower = int((gmt.tm_sec % 60 + (tm - int(tm))) / (60.0 / 65536.0 / 65536.0))
tid = pack('!LL', upper, lower)
if tid <= self.ltid:
upper, lower = unpack('!LL', self.ltid)
if lower == 0xffffffff:
# This should not happen usually.
from datetime import timedelta, datetime
hour, min = divmod(upper, 60)
day, hour = divmod(hour, 24)
month, day = divmod(day, 31)
year, month = divmod(month, 12)
d = datetime(year, month, day + 1, hour, min) + timedelta(0, 60)
upper = (((d.year * 12 + d.month) * 31 + d.day - 1) \
* 24 + d.hour) * 60 + d.minute
lower = 0
else:
lower += 1
tid = pack('!LL', upper, lower)
self.ltid = tid
return tid
def getPartition(self, oid_or_tid):
return unpack('!Q', oid_or_tid)[0] % self.num_partitions
import logging
from neo.handler import EventHandler
class MasterEventHandler(EventHandler):
......@@ -5,3 +7,60 @@ class MasterEventHandler(EventHandler):
def __init__(self, app):
self.app = app
EventHandler.__init__(self)
def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name):
raise NotImplementedError('this method must be overridden')
def handleAskPrimaryMaster(self, conn, packet):
raise NotImplementedError('this method must be overridden')
def handleAnnouncePrimaryMaster(self, conn, packet):
raise NotImplementedError('this method must be overridden')
def handleReelectPrimaryMaster(self, conn, packet):
raise NotImplementedError('this method must be overridden')
def handleNotifyNodeInformation(self, conn, packet, node_list):
logging.info('ignoring Notify Node Information')
pass
def handleAnswerLastIDs(self, conn, packet, loid, ltid, lptid):
logging.info('ignoring Answer Last IDs')
pass
def handleAnswerPartitionTable(self, conn, packet, cell_list):
logging.info('ignoring Answer Partition Table')
pass
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list):
logging.info('ignoring Answer Unfinished Transactions')
pass
def handleAnswerOIDsByTID(self, conn, packet, oid_list, tid):
logging.info('ignoring Answer OIDs By TID')
pass
def handleTidNotFound(self, conn, packet, message):
logging.info('ignoring Answer OIDs By TID')
pass
def handleAnswerObjectPresent(self, conn, packet, oid, tid):
logging.info('ignoring Answer Object Present')
pass
def handleOidNotFound(self, conn, packet, message):
logging.info('ignoring OID Not Found')
pass
def handleAskNewTID(self, conn, packet):
logging.info('ignoring Ask New TID')
pass
def handleFinishTransaction(self, conn, packet, oid_list, tid):
logging.info('ignoring Finish Transaction')
pass
def handleNotifyTransactionLocked(self, conn, packet, tid):
logging.info('ignoring Notify Transaction Locked')
pass
......@@ -327,22 +327,3 @@ class RecoveryEventHandler(MasterEventHandler):
app.nm.add(n)
app.pt.setCell(offset, n, state)
def handleAnswerUnfinishedTransactions(self, conn, packet, tid_list):
# This can be from previous verification stage.
pass
def handleAnswerOIDsByTID(self, conn, packet, oid_list, tid):
# This can be from previous verification stage.
pass
def handleTidNotFound(self, conn, packet, message):
# This can be from previous verification stage.
pass
def handleAnswerObjectPresent(self, conn, packet, oid, tid):
# This can be from previous verification stage.
pass
def handleOidNotFound(self, conn, packet, message):
# This can be from previous verification stage.
pass
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment