Exemplo n.º 1
0
# (C) 2018 The University of Chicago
# See COPYRIGHT in top-level directory.
import sys
sys.path.append('build/lib.linux-x86_64-3.7')
from pymargo.core import Engine
from pysdskv.client import *

engine = Engine('ofi+tcp')

server_addr = sys.argv[1]
provider_id = int(sys.argv[2])

client = SDSKVClient(engine)
addr = engine.lookup(server_addr)
provider_handle = client.create_provider_handle(addr, provider_id)

db = provider_handle.open("mydatabase")

db.put("matthieu", "*****@*****.**")
val = db.get("matthieu")
print("db.get('matthieu') returned " + str(val))
try:
    val = db.get("phil")
    print("db.get('phil') returned " + str(val))
except KeyError:
    print("Correctly throws an exception when trying to lookup 'phil'")
e = db.exists("matthieu")
print("db.exists('matthieu') returned " + str(e))
e = db.exists("phil")
print("db.exists('phil') returned " + str(e))
db.erase("matthieu")
Exemplo n.º 2
0
# (C) 2018 The University of Chicago
# See COPYRIGHT in top-level directory.
import sys
from pymargo.core import Engine
from pybake.target import BakeRegionID
from pybake.client import *
import numpy as np

mid = Engine('ofi+tcp')

server_addr = sys.argv[1]
mplex_id = int(sys.argv[2])

client = BakeClient(mid)
addr = mid.lookup(server_addr)
ph = client.create_provider_handle(addr, mplex_id)

# Testing get_eager_limit
lim = ph.get_eager_limit()
print "Eager limit is: " + str(lim)

# probe the provider handle (for all targets)
targets = ph.probe()
print "Probe found the following targets:"
for t in targets:
    print "===== " + str(t)

target = targets[0]

# write into a region
arr = np.random.randn(5, 6)
Exemplo n.º 3
0
class InWrapMochi:

	def __init__(self, transport, address, p_id, db_n):
		self.engine = Engine(transport)
		self.server_addr = address
		self.provider_id = p_id
		self.db_name = db_n

		# init the engine
		self.client = SDSKVClient(self.engine)
		self.addr = self.engine.lookup(self.server_addr)
		self.provider_handle = self.client.create_provider_handle(self.addr, self.provider_id)
		self.db = self.provider_handle.open(self.db_name)

		# create a dictionary for values
		self.command_dic = {}
		self.used_unique_ids = []
		self.count = 0

		self.addingKeys = False



	def put_keyval(self, key, val):
		self.db.put(key, val)


	def del_key(self, key):
		if (self.db.exists(key)):
			self.db.erase(key)
		else:
			return "key does not exist"


	def get_val(self, key):
		if (self.db.exists(key)):
			return self.db.get(key)
		else:
			return "key does not exist"


	def exists(self, key):
		return self.db.exists(key)


	def list_keyVal(self):
		key,val = self.db.list_keyvals()
		return key,val


	def shutdown(self):
		self.client.shutdown_service(self.addr)



	def getIP(self):
		hostname = socket.gethostname()    
		IPAddr = socket.gethostbyname(hostname)  
		return str(IPAddr)


	def generateHash(self, value):
		hash_object = hashlib.md5(value.encode())
		temp_str = str(hash_object.hexdigest())
		return ( temp_str[0:8] )


	# Transaction operations: Set and commit
	def set(self, key, value):
		self.command_dic[key + "-" + str(self.count)] = value
		self.count = self.count + 1


	def commit(self):

		ip_addr = self.getIP()
		hash_val = self.generateHash(ip_addr)
		new_key = "NEW_KEY_" + hash_val

		# Loop until you can add a new key
		while ( self.db.exists(new_key) ): 
			continue


		# Generate a random number to pad keys with
		#rand_num = random.randint(99999,1000000)
		#while rand_num in self.used_unique_ids:
		#	rand_num = random.randint(99999,1000000)

		#self.used_unique_ids.append(rand_num)

		# Format of keys:
		# XXXXXX:Key-YYY

		# Add keys to mochi DB
		key_list = []
		self.addingKeys = True
		#self.db.put("NEW_KEY", "0")	# adding keys
		for key,val in self.command_dic.items():
			key_padded = hash_val + ":" + key	# add unique tag to each
			#key_padded = key + ":" + str(rand_num)	# add unique tag to each
			self.db.put(key_padded, val)			# put key in mochi db

			key_list.append(key)	# save the key for later deletion

			print("key: ", key_padded)
			print("val: ", val)

		#self.db.put("NEW_KEY", str(rand_num))	# adding keys done
		self.db.put(new_key, hash_val)	# adding keys done
		self.addingKeys = False

		# Delete keys
		for k in key_list:
			del self.command_dic[k]
Exemplo n.º 4
0
class SeerClient:

    def __init__(self, transport, address, p_id, db_n):
        self.engine = Engine(transport)
        self.server_addr = address
        self.provider_id = p_id
        self.db_name = db_n

        # init the engine
        self.client = SDSKVClient(self.engine)
        self.addr = self.engine.lookup(self.server_addr)
        self.provider_handle = self.client.create_provider_handle(self.addr, self.provider_id)
        self.db = self.provider_handle.open(self.db_name)

        # create a dictionary for values
        self.command_dic = {}
        self.used_unique_ids = []
        self.count = 0

        self.addingKeys = False
  
        # Generate Hash
        ip_addr = self.__getIP()
        self.hash_val = self.__generateHash(ip_addr)
  
        # excluded keys
        self.removed_keys = []


    def __getIP(self):
        hostname = socket.gethostname()    
        IPAddr = socket.gethostbyname(hostname)  
        return str(IPAddr)


    def __generateHash(self, value):
        hash_object = hashlib.md5(value.encode())
        temp_str = str(hash_object.hexdigest())
        return ( temp_str[0:8] )


    # Some Utility functions
    def put_keyval(self, key, val):
        self.db.put(key, val)


    def del_key(self, key):
        if (self.db.exists(key)):
            self.db.erase(key)
        else:
            return "key " + key +" does not exist!"


    def get_val(self, key):
        if (self.db.exists(key)):
            return self.db.get(key)
        else:
            return "key " + key +" does not exist!"


    def exists(self, key):
        return self.db.exists(key)


    def list_keyVal(self):
        key,val = self.db.list_keyvals()
        return key,valvlist_keyvals


    def shutdown(self):
        self.client.shutdown_service(self.addr)
        
  
    
    # User Operations
    def list_keys(self):
        """List my keys and general ones"""
        keys,vals = self.list_keyVal()
  
        my_keys = []
        for k in keys:
            if k.startswith(self.hash_val) or k.startswith("00000000"): 
                if k not in self.removed_keys:
                    my_keys.append(k)
    
        return my_keys


    def list_my_keys_only(self):
        """List my keys only"""
        key,val = self.list_keyVal()
  
        my_keys = []
        for k in key:
            if k.startswith(self.hash_val):   #my keys only
                if k not in self.removed_keys:
                    my_keys.append(k)
    
        return my_keys
    
    
    def get_value_at_ts(self, key, timestep):
        num_ranks = self.get_val("numRanks")
        values = []
        for r in range( int(num_ranks) ):
            temp_key = self.hash_val + "@" + key + "#" + str(r) + "|" + str(timestep)
            values.append( self.get_val(temp_key) )
        
        return values
            
       
 
    def set(self, key, value):
        """Adds a command"""
  
        # Format of keys:
        #  NEW_KEY@HASH
        #  HASH@Type:Command%count
  
        self.command_dic[key + "%" + str(self.count)] = value
        self.count = self.count + 1
  
        # Append to the list of removed keys
        if key == "DEL":
            self.removed_keys.append(value)


    def commit(self):
        """Send commands to database"""
        new_key = "NEW_KEY@" + self.hash_val

        # Loop until you can add a new key
        while ( self.db.exists(new_key) ): 
            continue


        # Add keys to mochi DB
        key_list = []
        self.addingKeys = True

        for key,val in self.command_dic.items():
            key_padded = self.hash_val + "@" + key  # add unique tag to each
   
            self.db.put(key_padded, val)            # put key in mochi db

            key_list.append(key)                    # save the key for later deletion

            print("key: ", key_padded)
            print("val: ", val)

        self.db.put(new_key, self.hash_val)  # adding keys done
        self.addingKeys = False

        # Delete keys
        for k in key_list:              # delete keys that have been added to db
            del self.command_dic[k]