From 35c5c511b0a60018b0c567c08dd884f07239728e Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Sat, 25 Nov 2006 09:35:36 +0000 Subject: [PATCH] caching sites, connected to persons, and nodes Cache had a bug in handling simple (belongs_to-like) xrefs (e.g. site_id in persons) --- PLC/Cache.py | 19 +++++++++++++------ PLC/Nodes.py | 7 +++++-- PLC/Persons.py | 5 +++-- PLC/Sites.py | 14 ++++++++++++++ planetlab4.sql | 7 +++++-- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/PLC/Cache.py b/PLC/Cache.py index 10adeeb..97432af 100644 --- a/PLC/Cache.py +++ b/PLC/Cache.py @@ -4,7 +4,7 @@ from PLC.Filter import Filter from PLC.Table import Row, Table verbose_flag=False; -#verbose_flag=True; +verbose_flag=True; def verbose (*args): if verbose_flag: print (args) @@ -213,9 +213,9 @@ class Cache: field=xref_spec['field'] alien_xref_obj_list = alien_xref_objs_dict[xref_classname] alien_value = alien_object[field] + transcoder = accessories[xref_classname]['transcoder'] if isinstance (alien_value,list): verbose ('update_table list-transcoding ',xref_classname,' aliens=',alien_value,) - transcoder = accessories[xref_classname]['transcoder'] local_values=[] for a in alien_value: try: @@ -234,6 +234,7 @@ class Cache: former_xrefs, local_values) elif isinstance (alien_value,int): + verbose ('update_table atom-transcoding ',xref_classname,' aliens=',alien_value,) new_value = transcoder.transcode(alien_value) local_object[field] = new_value local_object.sync() @@ -259,6 +260,11 @@ class Cache: # requires to know remote peer's peer_id for ourselves, mmhh.. # does not make any difference in a 2-peer deployment though + # refresh sites + all_sites = self.peer_server.GetSites(self.auth) + local_sites = self.get_locals (all_sites) + nb_new_sites = self.update_table('Site', local_sites) + # refresh keys all_keys = self.peer_server.GetKeys(self.auth) local_keys = self.get_locals (all_keys) @@ -267,13 +273,14 @@ class Cache: # refresh nodes all_nodes = self.peer_server.GetNodes(self.auth) local_nodes = self.get_locals(all_nodes) - nb_new_nodes = self.update_table('Node', local_nodes) + nb_new_nodes = self.update_table('Node', local_nodes, + { 'Site' : all_sites } ) # refresh persons all_persons = self.peer_server.GetPersons(self.auth) local_persons = self.get_locals(all_persons) nb_new_persons = self.update_table ('Person', local_persons, - { 'Key': all_keys} ) + { 'Key': all_keys, 'Site' : all_sites } ) # refresh slices local_slices = self.peer_server.GetSlices(self.auth,{'peer_id':None}) @@ -282,11 +289,11 @@ class Cache: return slice['creator_person_id'] == 1 nb_new_slices = self.update_table ('Slice', local_slices, - {'Node': all_nodes, - 'Person': all_persons}, + {'Node': all_nodes, 'Person': all_persons}, is_system_slice) return {'plcname':self.api.config.PLC_NAME, + 'new_sites':nb_new_sites, 'new_keys':nb_new_keys, 'new_nodes':nb_new_nodes, 'new_persons':nb_new_persons, diff --git a/PLC/Nodes.py b/PLC/Nodes.py index 3c7dae6..b57a677 100644 --- a/PLC/Nodes.py +++ b/PLC/Nodes.py @@ -4,7 +4,7 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: Nodes.py,v 1.22 2006/11/23 11:55:24 thierry Exp $ +# $Id: Nodes.py,v 1.23 2006/11/23 19:35:38 thierry Exp $ # from types import StringTypes @@ -65,7 +65,10 @@ class Node(Row): # for Cache class_key = 'hostname' foreign_fields = ['boot_state','model','version','date_created','last_updated'] - foreign_xrefs = {} + foreign_xrefs = { + # in this case, we dont need the 'table' but Cache will look it up, so... + 'Site' : { 'field' : 'site_id' , 'table' : 'unused' } , + } def validate_hostname(self, hostname): if not valid_hostname(hostname): diff --git a/PLC/Persons.py b/PLC/Persons.py index b519302..822a27f 100644 --- a/PLC/Persons.py +++ b/PLC/Persons.py @@ -4,7 +4,7 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: Persons.py,v 1.19 2006/11/09 19:43:55 mlhuang Exp $ +# $Id: Persons.py,v 1.20 2006/11/24 12:06:00 thierry Exp $ # from types import StringTypes @@ -60,7 +60,8 @@ class Person(Row): #foreign_xrefs = { 'Node' : { 'field' : 'node_ids' , # 'table': 'slice_node' } } foreign_xrefs = { - 'Key' : { 'field' : 'key_ids', 'table' : 'person_key' } + 'Key' : { 'field' : 'key_ids', 'table' : 'person_key' } , + 'Site' : { 'field' : 'site_ids', 'table' : 'person_site'}, # 'key_ids': Parameter([int], "List of key identifiers"), # 'role_ids': Parameter([int], "List of role identifiers"), # 'roles': Parameter([str], "List of roles"), diff --git a/PLC/Sites.py b/PLC/Sites.py index 7474f03..84afa16 100644 --- a/PLC/Sites.py +++ b/PLC/Sites.py @@ -40,8 +40,22 @@ class Site(Row): 'address_ids': Parameter([int], "List of address identifiers"), 'pcu_ids': Parameter([int], "List of PCU identifiers"), 'node_ids': Parameter([int], "List of site node identifiers"), + 'peer_id': Parameter(int, "Peer at which this slice was created", nullok = True), } + # for Cache + class_key = 'login_base' + foreign_fields = ['abbreviated_name', 'name', 'is_public', 'latitude', 'longitude', + 'url', 'date_created', 'last_updated', 'max_slices', 'max_slivers', + ] + foreign_xrefs = { +#'person_ids', +#'slice_ids', +#'node_ids', +#'address_ids', +#'pcu_ids', +} + def validate_name(self, name): if not len(name): raise PLCInvalidArgument, "Name must be specified" diff --git a/planetlab4.sql b/planetlab4.sql index 54afd43..2b3b4c3 100644 --- a/planetlab4.sql +++ b/planetlab4.sql @@ -9,7 +9,7 @@ -- -- Copyright (C) 2006 The Trustees of Princeton University -- --- $Id: planetlab4.sql,v 1.43 2006/11/23 19:35:38 thierry Exp $ +-- $Id: planetlab4.sql,v 1.44 2006/11/24 12:05:59 thierry Exp $ -- -------------------------------------------------------------------------------- @@ -108,7 +108,9 @@ CREATE TABLE sites ( -- Timestamps date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, - last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, + + peer_id integer REFERENCES peers -- From which peer ) WITH OIDS; CREATE INDEX sites_login_base_idx ON sites (login_base) WHERE deleted IS false; @@ -913,6 +915,7 @@ sites.max_slivers, sites.latitude, sites.longitude, sites.url, +sites.peer_id, CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created, CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated, COALESCE(site_persons.person_ids, '{}') AS person_ids, -- 2.43.0