public Versioned Get(byte[] key, Versioned defaultValue)
        {
            for (int attempts = 0; attempts < METADATA_REFRESH_ATTEMPTS; attempts++)
            {
                try
                {
                    Versioned curValue = null;
                    IList<Versioned> items = _Store.get(key);
                    if (items.Count == 0)
                    {
                        if (null == defaultValue)
                            return null;
                        curValue = defaultValue;
                    }
                    else if (items.Count == 1)
                        curValue = items[0];
                    else
                        throw new InconsistentDataException("Unresolved versions returned from get(" + key + ")");

                    return curValue;
                }
                catch (InvalidMetadataException ex)
                {
                    if (log.IsErrorEnabled) log.Error("Exception thrown", ex);
                    reinit();
                }
            }

            throw new InvalidMetadataException("Exceeded maximum metadata refresh attempts");

        }
Example #2
0
        public void put(byte[] key, Versioned value)
        {
            try
            {
                using (Connection conn = Pool.Checkout(this.Host, this.Port, request.getNegotiationString()))
                {
                    try
                    {
                        request.writePutRequest(conn.Stream,
                            this.Name,
                            key,
                            value.value,
                            (VectorClock)value.version,
                            this.ShouldReroute);
                        conn.Stream.Flush();

                        request.readPutResponse(conn.Stream);
                    }
                    catch
                    {
                        conn.Errored = true;
                        throw;
                    }
                }
            }
            catch (UnreachableStoreException ex)
            {
                if (log.IsErrorEnabled) log.Error("Failure to get " + Host, ex);
                throw new UnreachableStoreException("Failure to get " + Host, ex);
            }
        }
 public void UpdateMetadata(byte[] key, Versioned versioned)
 {
     throw new NotImplementedException();
 }
        public void Put(byte[] key, byte[] value)
        {
            Versioned vv = Get(key);

            if (null == vv)
            {
                try
                {
                    vv = new Versioned() { value = value, version = new VectorClock() };
                }
                catch (InvalidMetadataException ex)
                {
                    if (log.IsErrorEnabled) log.Error("Exception thrown", ex);
                }
            }
            else
            {
                vv.value = value;
            }

            Put(key, vv);
        }
 public bool DeleteKey(byte[] key, Versioned version)
 {
     for (int attempts = 0; attempts < METADATA_REFRESH_ATTEMPTS; attempts++)
     {
         try
         {
             return _Store.deleteKey(key, version);
         }
         catch (InvalidMetadataException)
         {
             reinit();
         }
     }
     throw new InvalidMetadataException("Exceeded maximum metadata refresh attempts");
 }
 public void Put(byte[] key, Versioned value)
 {
     for (int attempts = 0; attempts < METADATA_REFRESH_ATTEMPTS; attempts++)
     {
         try
         {
             _Store.put(key, value);
             return;
         }
         catch (InvalidMetadataException ex)
         {
             if (log.IsErrorEnabled) log.Error("Exception thrown while calling put on store " + _Store.Name, ex);
             reinit();
         }
     }
     throw new InvalidMetadataException("Exceeded maximum metadata refresh attempts");
 }
 public bool PutifNotObsolete(byte[] key, Versioned value)
 {
     try
     {
         Put(key, value);
         return true;
     }
     catch (ObsoleteVersionException)
     {
         //TODO:Revisit this. F**k throwing an exception if we don't need to.
         return false;
     }
 }
Example #8
0
        public bool deleteKey(byte[] key, Versioned version)
        {
            bool status = false;
            bool result = false;
            IList<Node> prefList = _routingStrategy.routeRequest(key);
            IList<Node> availableNodes = Node.GetAvailableNodes(prefList);
            foreach (Node node in availableNodes)
            {
                status = doDeleteFromStore(key, version, node, _clusterMap[node.ID], out result);

                if (status)
                    return result;
            }

            foreach (Node node in _cluster.NodeMap.Values)
            {
                status = doDeleteFromStore(key, version, node, _clusterMap[node.ID], out result);

                if (status)
                    return result;
            }

            throw new InsufficientOperationalNodesException("Could not reach any node for get operation");
        }
Example #9
0
        public void put(byte[] key, Versioned value)
        {
            bool status = false;
            
            IList<Node> prefList = _routingStrategy.routeRequest(key);
            IList<Node> availableNodes = Node.GetAvailableNodes(prefList);
            foreach (Node node in availableNodes)
            {
                status = doPutFromStore(key, value, node, _clusterMap[node.ID]);

                if (status)
                    return;
            }

            foreach (Node node in _cluster.NodeMap.Values)
            {
                status = doPutFromStore(key, value, node, _clusterMap[node.ID]);

                if (status)
                    return;
            }

            throw new InsufficientOperationalNodesException("Could not reach any node for get operation");
        }
Example #10
0
 static bool doDeleteFromStore(byte[] key,
                       Versioned version,
                       Node node,
                       Store store,
                       out bool result)
 {
     try
     {
         result = store.deleteKey(key, version);
         node.SetAvailable(); //TODO: Check the cpp source for node and what's it's doing.
         return true;
     }
     catch (UnreachableStoreException ex)
     {
         if (log.IsErrorEnabled) log.Error("Exception while calling store.get on " + node, ex);
         node.SetDown();
     }
     catch (System.Net.Sockets.SocketException ex)
     {
         if (log.IsErrorEnabled) log.Error("Exception while calling store.get on " + node, ex);
         node.SetDown();
     }
     catch (Exception ex)
     {
         if (log.IsErrorEnabled) log.Error("Exception while calling store.get on " + node, ex);
         node.SetDown();
     }
     finally
     {
         node.Requests++;
     }
     result = false;
     return false;
 }
 public bool deleteKey(byte[] key, Versioned version)
 {
     return _substore.deleteKey(key, version);
 }
 public void put(byte[] key, Versioned value)
 {
     _substore.put(key, value);
 }