Ejemplo n.º 1
0
        private static void Main()
        {
            TTransport framedTransport = new TFramedTransport(new TSocket("localhost", 9160));
            TTransport socketTransport = new TSocket("localhost", 9160);
            TProtocol framedProtocol = new TBinaryProtocol(framedTransport);
            TProtocol socketProtocol = new TBinaryProtocol(socketTransport);

            var client = new Cassandra.Client(framedProtocol, framedProtocol); // all framed
            //var client = new Cassandra.Client(socketProtocol, socketProtocol); // all socket
            //var client = new Cassandra.Client(framedProtocol, socketProtocol); // in: framed out: socket
            //var client = new Cassandra.Client(socketProtocol, framedProtocol); // in: socket out: framed

            framedTransport.Open();
            socketTransport.Open();
            Console.WriteLine("Start");

            client.set_keyspace("Keyspace1");

            Console.WriteLine("Count Key");
            var key = Encoding.ASCII.GetBytes("MyKey");
            var columns = new List<byte[]>(new[] { Encoding.ASCII.GetBytes("MyColumn") });
            var column_parent = new ColumnParent {
                Column_family = "Standard1"
            };
            var predicate = new SlicePredicate {
                Column_names = columns
            };
            client.get_count(key, column_parent, predicate, ConsistencyLevel.ALL);

            Console.WriteLine("Done");
            Console.Read();
        }
Ejemplo n.º 2
0
        public void Read(TProtocol iprot)
        {
            TField field;

            iprot.ReadStructBegin();
            while (true)
            {
                field = iprot.ReadFieldBegin();
                if (field.Type == TType.Stop)
                {
                    break;
                }
                switch (field.ID)
                {
                case 1:
                    if (field.Type == TType.I64)
                    {
                        this.timestamp         = iprot.ReadI64();
                        this.__isset.timestamp = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 2:
                    if (field.Type == TType.String)
                    {
                        this.super_column         = iprot.ReadBinary();
                        this.__isset.super_column = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                case 3:
                    if (field.Type == TType.Struct)
                    {
                        this.predicate = new SlicePredicate();
                        this.predicate.Read(iprot);
                        this.__isset.predicate = true;
                    }
                    else
                    {
                        TProtocolUtil.Skip(iprot, field.Type);
                    }
                    break;

                default:
                    TProtocolUtil.Skip(iprot, field.Type);
                    break;
                }
                iprot.ReadFieldEnd();
            }
            iprot.ReadStructEnd();
        }
Ejemplo n.º 3
0
 public int get_count(byte[] key, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
 {
     send_get_count(key, column_parent, predicate, consistency_level);
     return recv_get_count();
 }
Ejemplo n.º 4
0
 public void Read(TProtocol iprot)
 {
     TField field;
     iprot.ReadStructBegin();
     while (true)
     {
       field = iprot.ReadFieldBegin();
       if (field.Type == TType.Stop) {
     break;
       }
       switch (field.ID)
       {
     case 1:
       if (field.Type == TType.String) {
     Key = iprot.ReadBinary();
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 2:
       if (field.Type == TType.Struct) {
     Column_parent = new ColumnParent();
     Column_parent.Read(iprot);
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 3:
       if (field.Type == TType.Struct) {
     Predicate = new SlicePredicate();
     Predicate.Read(iprot);
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 4:
       if (field.Type == TType.I32) {
     Consistency_level = (ConsistencyLevel)iprot.ReadI32();
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     default:
       TProtocolUtil.Skip(iprot, field.Type);
       break;
       }
       iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }
Ejemplo n.º 5
0
 public void send_get_range_slices(ColumnParent column_parent, SlicePredicate predicate, KeyRange range, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("get_range_slices", TMessageType.Call, seqid_));
     get_range_slices_args args = new get_range_slices_args();
     args.Column_parent = column_parent;
     args.Predicate = predicate;
     args.Range = range;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
Ejemplo n.º 6
0
 public void send_get_count(byte[] key, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("get_count", TMessageType.Call, seqid_));
     get_count_args args = new get_count_args();
     args.Key = key;
     args.Column_parent = column_parent;
     args.Predicate = predicate;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
Ejemplo n.º 7
0
 public Dictionary<byte[], int> multiget_count(List<byte[]> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
 {
     send_multiget_count(keys, column_parent, predicate, consistency_level);
     return recv_multiget_count();
 }
Ejemplo n.º 8
0
 public List<KeySlice> get_range_slices(ColumnParent column_parent, SlicePredicate predicate, KeyRange range, ConsistencyLevel consistency_level)
 {
     send_get_range_slices(column_parent, predicate, range, consistency_level);
     return recv_get_range_slices();
 }
Ejemplo n.º 9
0
        public InventoryFolderBase GetFolderAttributes(UUID folderId)
        {
            if (folderId == UUID.Zero) throw new InventorySecurityException("Not returning folder with ID UUID.Zero");

            try
            {
                ColumnParent columnParent = new ColumnParent();
                columnParent.Column_family = FOLDERS_CF;
                columnParent.Super_column = ByteEncoderHelper.UTF8Encoder.ToByteArray("properties");

                SlicePredicate pred = new SlicePredicate();
                SliceRange range = new SliceRange();
                range.Start = new byte[0];
                range.Finish = new byte[0];
                range.Reversed = false;
                range.Count = int.MaxValue;
                pred.Slice_range = range;

                byte[] folderIdArray = ByteEncoderHelper.GuidEncoder.ToByteArray(folderId.Guid);

                ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
                object val =
                    cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                    {
                        return client.get_slice(folderIdArray, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                    }), KEYSPACE);

                List<ColumnOrSuperColumn> cols = (List<ColumnOrSuperColumn>)val;
                if (cols.Count == 0)
                {
                    throw new InventoryObjectMissingException(String.Format("Folder with ID {0} could not be found", folderId));
                }

                InventoryFolderBase folder = DecodeFolderBase(folderId.Guid, cols);

                //grab the folder version
                ColumnPath path = new ColumnPath
                {
                    Column = ByteEncoderHelper.UTF8Encoder.ToByteArray("count"),
                    Column_family = FOLDERVERSIONS_CF
                };


                object verVal =
                    cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                    {
                        return client.get(folderIdArray, path, DEFAULT_CONSISTENCY_LEVEL);

                    }), KEYSPACE);

                ColumnOrSuperColumn verColumn = (ColumnOrSuperColumn)verVal;

                folder.Version = (ushort)(verColumn.Counter_column.Value % (long)ushort.MaxValue);

                return folder;
            }
            catch (InventoryObjectMissingException e)
            {
//                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to retrieve folder attributes: {0}", e);
                throw; // produces a duplicate error farther up with more context
            }
            catch (Exception e)
            {
//                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to retrieve folder attributes: {0}", e);
                throw new InventoryStorageException(e.Message, e); // produces another error farther up with more context
            }
        }
Ejemplo n.º 10
0
        public InventoryItemBase GetItem(UUID itemId, UUID parentFolderHint)
        {
            //Retrieving an item requires a lookup of the parent folder followed by 
            //a retrieval of the item. This was a consious decision made since the 
            //inventory item data currently takes up the most space and a
            //duplication of this data to prevent the index lookup 
            //would be expensive in terms of space required

            try
            {
                Guid parentId;
                
                if (parentFolderHint != UUID.Zero)
                {
                    parentId = parentFolderHint.Guid;
                }
                else
                {
                    parentId = FindItemParentFolderId(itemId);
                }

                if (parentId == Guid.Empty)
                {
                    throw new InventoryObjectMissingException(String.Format("Item with ID {0} could not be found", itemId), "Item was not found in the index");
                }

                //try to retrieve the item. note that even though we have an index there is a chance we will
                //not have the item data due to a race condition between index mutation and item mutation
                byte[] itemIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(itemId.Guid);
                byte[] folderIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(parentId);

                ColumnParent columnParent = new ColumnParent();
                columnParent.Column_family = FOLDERS_CF;
                columnParent.Super_column = itemIdBytes;

                SlicePredicate pred = new SlicePredicate();
                SliceRange range = new SliceRange();
                range.Start = new byte[0];
                range.Finish = new byte[0];
                range.Reversed = false;
                range.Count = int.MaxValue;
                pred.Slice_range = range;

                ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);

                object itemDataObj =
                    cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                    {
                        return client.get_slice(folderIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                    }), KEYSPACE);

                List<ColumnOrSuperColumn> itemCols = (List<ColumnOrSuperColumn>)itemDataObj;

                if (itemCols.Count == 0)
                {
                    throw new InventoryObjectMissingException(String.Format("Item with ID {0} could not be found", itemId), "Item was not found in its folder");
                }

                InventoryItemBase item = this.DecodeInventoryItem(itemCols, itemId.Guid, parentId);

                return item;
            }
            catch (InventoryStorageException)
            {
                throw;
            }
            catch (Exception e)
            {
                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to retrieve item {0}: {1}", itemId, e);
                throw new InventoryStorageException(e.Message, e);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Retrieves a set of items in the same folder. This should be efficient compared to
        /// retrieving each item separately regardless of parent. This will be mostly used
        /// for gestures which are usually all in the same folder anyways
        /// </summary>
        /// <param name="folderId"></param>
        /// <param name="itemIds"></param>
        /// <returns></returns>
        private List<InventoryItemBase> GetItemsInSameFolder(UUID folderId, IEnumerable<UUID> itemIds, bool throwOnItemMissing)
        {
            byte[] folderIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(folderId.Guid);

            ColumnParent columnParent = new ColumnParent();
            columnParent.Column_family = FOLDERS_CF;

            SlicePredicate pred = new SlicePredicate();
            pred.Column_names = new List<byte[]>();
            foreach (UUID id in itemIds)
            {
                pred.Column_names.Add(ByteEncoderHelper.GuidEncoder.ToByteArray(id.Guid));
            }

            ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);

            object itemDataObj =
                cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                {
                    return client.get_slice(folderIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                }), KEYSPACE);

            List<ColumnOrSuperColumn> itemCols = (List<ColumnOrSuperColumn>)itemDataObj;

            if (throwOnItemMissing && itemCols.Count != pred.Column_names.Count)
            {
                throw new InventoryObjectMissingException("One or more items requested could not be found");
            }

            List<InventoryItemBase> retItems = new List<InventoryItemBase>();
            foreach (ColumnOrSuperColumn superCol in itemCols)
            {
                Guid itemId = ByteEncoderHelper.GuidEncoder.FromByteArray(superCol.Super_column.Name);
                InventoryItemBase item = this.DecodeInventoryItem(superCol.Super_column.Columns, itemId, folderId.Guid);
                retItems.Add(item);
            }

            return retItems;
        }
Ejemplo n.º 12
0
        public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
        {
            try
            {
                Dictionary<Guid, InventoryFolderBase> index = GetFolderIndex(userId);
                if (index.Count == 0)
                {
                    return new List<InventoryFolderBase>();
                }

                List<byte[]> keys = new List<byte[]>(index.Count);
                foreach (KeyValuePair<Guid, InventoryFolderBase> indexInfo in index)
                {
                    keys.Add(ByteEncoderHelper.GuidEncoder.ToByteArray(indexInfo.Value.ID.Guid));
                }


                //retrieve the versions for all folders
                ColumnParent versionParent = new ColumnParent
                {
                    Column_family = FOLDERVERSIONS_CF,
                };

                SlicePredicate versionPred = new SlicePredicate();
                versionPred.Column_names = new List<byte[]> { ByteEncoderHelper.UTF8Encoder.ToByteArray("count") };

                Dictionary<byte[], List<ColumnOrSuperColumn>> verColumns =
                    this.RetrieveRowsInChunks(FOLDER_VERSION_CHUNK_SZ, keys, versionParent, versionPred, DEFAULT_CONSISTENCY_LEVEL);

                foreach (KeyValuePair<byte[], List<ColumnOrSuperColumn>> kvp in verColumns)
                {
                    Guid fid = ByteEncoderHelper.GuidEncoder.FromByteArray(kvp.Key);

                    InventoryFolderBase f;
                    if (index.TryGetValue(fid, out f))
                    {
                        if (kvp.Value.Count == 1)
                        {
                            f.Version = (ushort)(kvp.Value[0].Counter_column.Value % (long)ushort.MaxValue);
                        }
                    }
                }

                return new List<InventoryFolderBase>(index.Values);
            }
            catch (Exception e)
            {
                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to retrieve folder skeleton: {0}", e);
                throw new InventoryStorageException(e.Message, e);
            }
        }
Ejemplo n.º 13
0
 public void Read(TProtocol iprot)
 {
     TField field;
       iprot.ReadStructBegin();
       while (true)
       {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) {
       break;
     }
     switch (field.ID)
     {
       case 1:
     if (field.Type == TType.I64) {
       Timestamp = iprot.ReadI64();
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 2:
     if (field.Type == TType.String) {
       Super_column = iprot.ReadBinary();
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 3:
     if (field.Type == TType.Struct) {
       Predicate = new SlicePredicate();
       Predicate.Read(iprot);
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       default:
     TProtocolUtil.Skip(iprot, field.Type);
     break;
     }
     iprot.ReadFieldEnd();
       }
       iprot.ReadStructEnd();
 }
Ejemplo n.º 14
0
 public void send_multiget_count(List<byte[]> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
 #endif
 {
   oprot_.WriteMessageBegin(new TMessage("multiget_count", TMessageType.Call, seqid_));
   multiget_count_args args = new multiget_count_args();
   args.Keys = keys;
   args.Column_parent = column_parent;
   args.Predicate = predicate;
   args.Consistency_level = consistency_level;
   args.Write(oprot_);
   oprot_.WriteMessageEnd();
   #if SILVERLIGHT
   return oprot_.Transport.BeginFlush(callback, state);
   #else
   oprot_.Transport.Flush();
   #endif
 }
Ejemplo n.º 15
0
 public IAsyncResult send_multiget_count(AsyncCallback callback, object state, List<byte[]> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
Ejemplo n.º 16
0
        public void Read(TProtocol iprot)
        {
            iprot.IncrementRecursionDepth();
            try
            {
                TField field;
                iprot.ReadStructBegin();
                while (true)
                {
                    field = iprot.ReadFieldBegin();
                    if (field.Type == TType.Stop)
                    {
                        break;
                    }
                    switch (field.ID)
                    {
                    case 1:
                        if (field.Type == TType.I64)
                        {
                            Timestamp = iprot.ReadI64();
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    case 2:
                        if (field.Type == TType.String)
                        {
                            Super_column = iprot.ReadBinary();
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    case 3:
                        if (field.Type == TType.Struct)
                        {
                            Predicate = new SlicePredicate();
                            Predicate.Read(iprot);
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    default:
                        TProtocolUtil.Skip(iprot, field.Type);
                        break;
                    }
                    iprot.ReadFieldEnd();
                }
                iprot.ReadStructEnd();
            }
            finally
            {
                iprot.DecrementRecursionDepth();
            }
        }
Ejemplo n.º 17
0
        public InventoryFolderBase GetFolder(UUID folderId)
        {
            if (folderId == UUID.Zero) throw new InventorySecurityException("Not returning folder with ID UUID.Zero");

            try
            {
                ColumnParent columnParent = new ColumnParent();
                columnParent.Column_family = FOLDERS_CF;

                SlicePredicate pred = new SlicePredicate();
                SliceRange range = new SliceRange();
                range.Start = new byte[0];
                range.Finish = new byte[0];
                range.Reversed = false;
                range.Count = int.MaxValue;
                pred.Slice_range = range;

                byte[] folderIdArray = ByteEncoderHelper.GuidEncoder.ToByteArray(folderId.Guid);

                ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
                List<ColumnOrSuperColumn> cols = this.RetrieveAllColumnsInChunks(FOLDER_CONTENTS_CHUNK_SZ,
                    folderIdArray, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                if (cols.Count == 0)
                {
                    throw new InventoryObjectMissingException(String.Format("Folder with ID {0} could not be found", folderId));
                }

                ParsedFolderData parsedData = new ParsedFolderData(cols);
                InventoryFolderBase folder = DecodeFolderBase(folderId.Guid, parsedData.Properties.Super_column.Columns);

                if (parsedData.SubFolders != null)
                {
                    foreach (Column col in parsedData.SubFolders.Super_column.Columns)
                    {
                        SubFolderData data = SubFolderData.FromByteArray(col.Value);
                        InventorySubFolderBase folderStub = new InventorySubFolderBase
                        {
                            ID = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Name)),
                            Name = data.Name,
                            Owner = folder.Owner,
                            Type = data.Type
                        };

                        folder.SubFolders.Add(folderStub);
                    }
                }

                foreach (ColumnOrSuperColumn itemCol in parsedData.Items)
                {
                    Guid itemId = ByteEncoderHelper.GuidEncoder.FromByteArray(itemCol.Super_column.Name);
                    InventoryItemBase item = this.DecodeInventoryItem(itemCol.Super_column.Columns, itemId, folder.ID.Guid);

                    folder.Items.Add(item);
                }

                //grab the folder version
                try
                {
                    ColumnPath path = new ColumnPath
                    {
                        Column = ByteEncoderHelper.UTF8Encoder.ToByteArray("count"),
                        Column_family = FOLDERVERSIONS_CF
                    };

                    object verVal =
                        cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                        {
                            return client.get(folderIdArray, path, DEFAULT_CONSISTENCY_LEVEL);

                        }), KEYSPACE);

                    ColumnOrSuperColumn verColumn = (ColumnOrSuperColumn)verVal;

                    folder.Version = (ushort)(verColumn.Counter_column.Value % (long)ushort.MaxValue);
                }
                catch (Exception e)
                {
                    _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Could not retrieve the version for folder {0} substituting 1: {1}", folderId, e);

                    //version column missing. this is either a partially deleted folder
                    //or the version mutation never happened. Return 1
                    folder.Version = 1;
                }

                return folder;
            }
            catch (InventoryObjectMissingException e)
            {
                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to retrieve folder attributes: {0}", e);
                throw;
            }
            catch (Exception e)
            {
                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to retrieve folder attributes: {0}", e);
                throw new InventoryStorageException(e.Message, e);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Retrieves all the rows for the given list of keys in chunkSize chunks
        /// </summary>
        /// <param name="chunkSize"></param>
        /// <param name="allKeys"></param>
        /// <param name="colParent"></param>
        /// <param name="pred"></param>
        /// <param name="consistencyLevel"></param>
        /// <returns></returns>
        private Dictionary<byte[], List<ColumnOrSuperColumn>> RetrieveRowsInChunks(int chunkSize, List<byte[]> allKeys,
            ColumnParent colParent, SlicePredicate pred, ConsistencyLevel consistencyLevel)
        {
            ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);

            if (allKeys.Count <= chunkSize)
            {
                object val =
                    cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                    {
                        return client.multiget_slice(allKeys, colParent, pred, consistencyLevel);

                    }), KEYSPACE);

                return (Dictionary<byte[], List<ColumnOrSuperColumn>>)val;
            }
            else
            {
                Dictionary<byte[], List<ColumnOrSuperColumn>> ret = new Dictionary<byte[], List<ColumnOrSuperColumn>>();

                for (int i = 0; i < allKeys.Count; i += chunkSize)
                {
                    int remaining = allKeys.Count - i;
                    List<byte[]> keys = allKeys.GetRange(i, remaining >= chunkSize ? chunkSize : remaining);

                    object val =
                    cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                    {
                        return client.multiget_slice(keys, colParent, pred, consistencyLevel);

                    }), KEYSPACE);

                    Dictionary<byte[], List<ColumnOrSuperColumn>> chunk = (Dictionary<byte[], List<ColumnOrSuperColumn>>)val;
                    foreach(KeyValuePair<byte[], List<ColumnOrSuperColumn>> kvp in chunk)
                    {
                        ret.Add(kvp.Key, kvp.Value);
                    }
                }

                return ret;
            }
            
        }
Ejemplo n.º 19
0
 public void Read(TProtocol iprot)
 {
     TField field;
       iprot.ReadStructBegin();
       while (true)
       {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) {
       break;
     }
     switch (field.ID)
     {
       case 1:
     if (field.Type == TType.Struct) {
       this.clock = new Clock();
       this.clock.Read(iprot);
       this.__isset.clock = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 2:
     if (field.Type == TType.String) {
       this.super_column = iprot.ReadBinary();
       this.__isset.super_column = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 3:
     if (field.Type == TType.Struct) {
       this.predicate = new SlicePredicate();
       this.predicate.Read(iprot);
       this.__isset.predicate = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       default:
     TProtocolUtil.Skip(iprot, field.Type);
     break;
     }
     iprot.ReadFieldEnd();
       }
       iprot.ReadStructEnd();
 }
Ejemplo n.º 20
0
        public Guid FindItemParentFolderId(UUID itemId)
        {
            ColumnParent columnParent = new ColumnParent();
            columnParent.Column_family = ITEMPARENTS_CF;

            SlicePredicate pred = new SlicePredicate();
            SliceRange range = new SliceRange();
            range.Start = new byte[0];
            range.Finish = new byte[0];
            range.Reversed = false;
            range.Count = int.MaxValue;
            pred.Slice_range = range;

            byte[] itemIdArray = ByteEncoderHelper.GuidEncoder.ToByteArray(itemId.Guid);

            ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);

            object val = 
                cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                {
                    return client.get_slice(itemIdArray, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                }), KEYSPACE);

            List<ColumnOrSuperColumn> indexCols = (List<ColumnOrSuperColumn>)val;

            //no index means the item doesnt exist
            if (indexCols.Count == 0)
            {
                return Guid.Empty;
            }

            var indexedColsByName = this.IndexColumnsByUTF8Name(indexCols);

            return ByteEncoderHelper.GuidEncoder.FromByteArray(indexedColsByName["parent"].Value);
        }
Ejemplo n.º 21
0
 public List<ColumnOrSuperColumn> get_slice(byte[] key, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
 {
     send_get_slice(key, column_parent, predicate, consistency_level);
     return recv_get_slice();
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Returns a dictionary of parents with a list of items Dictionary[FolderID, List[Items]] 
        /// </summary>
        /// <param name="itemIds"></param>
        /// <returns></returns>
        public Dictionary<UUID, List<UUID>> FindItemParentFolderIds(IEnumerable<UUID> itemIds)
        {
            ColumnParent columnParent = new ColumnParent();
            columnParent.Column_family = ITEMPARENTS_CF;

            SlicePredicate pred = new SlicePredicate();
            pred.Column_names = new List<byte[]>();
            pred.Column_names.Add(ByteEncoderHelper.UTF8Encoder.ToByteArray("parent"));

            List<byte[]> allItemIdBytes = new List<byte[]>();
            foreach (UUID id in itemIds)
            {
                allItemIdBytes.Add(ByteEncoderHelper.GuidEncoder.ToByteArray(id.Guid));
            }

            ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);

            object val =
                cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                {
                    return client.multiget_slice(allItemIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                }), KEYSPACE);

            Dictionary<byte[], List<ColumnOrSuperColumn>> itemParentCols = (Dictionary<byte[], List<ColumnOrSuperColumn>>)val;
            Dictionary<UUID, List<UUID>> retParents = new Dictionary<UUID, List<UUID>>();

            foreach (KeyValuePair<byte[], List<ColumnOrSuperColumn>> kvp in itemParentCols)
            {
                if (kvp.Value.Count == 1)
                {
                    Column col = kvp.Value[0].Column;

                    UUID parentId = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Value));

                    if (!retParents.ContainsKey(parentId))
                    {
                        retParents.Add(parentId, new List<UUID>());
                    }

                    retParents[parentId].Add(new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(kvp.Key)));
                }
            }

            return retParents;
        }
Ejemplo n.º 23
0
 public Dictionary<byte[], List<ColumnOrSuperColumn>> multiget_slice(List<byte[]> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
 {
     send_multiget_slice(keys, column_parent, predicate, consistency_level);
     return recv_multiget_slice();
 }
Ejemplo n.º 24
0
        private List<UUID> GetActiveGestureItemIds(UUID userId)
        {
            try
            {
                ColumnParent columnParent = new ColumnParent();
                columnParent.Column_family = USERACTIVEGESTURES_CF;

                SlicePredicate pred = new SlicePredicate();
                SliceRange range = new SliceRange();
                range.Start = new byte[0];
                range.Finish = new byte[0];
                range.Reversed = false;
                range.Count = int.MaxValue;
                pred.Slice_range = range;

                ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);

                object retobj =
                    cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                    {
                        byte[] userIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(userId.Guid);
                        return client.get_slice(userIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);
                    
                    }), KEYSPACE);

                List<ColumnOrSuperColumn> cols = (List<ColumnOrSuperColumn>)retobj;
                List<UUID> ret = new List<UUID>();

                foreach (ColumnOrSuperColumn col in cols)
                {
                    ret.Add(new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Column.Name)));
                }

                return ret;
            }
            catch (Exception e)
            {
                throw new InventoryStorageException(e.Message, e);
            }
        }
Ejemplo n.º 25
0
 public void send_get_indexed_slices(ColumnParent column_parent, IndexClause index_clause, SlicePredicate column_predicate, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("get_indexed_slices", TMessageType.Call, seqid_));
     get_indexed_slices_args args = new get_indexed_slices_args();
     args.Column_parent = column_parent;
     args.Index_clause = index_clause;
     args.Column_predicate = column_predicate;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
Ejemplo n.º 26
0
        private List<ColumnOrSuperColumn> RetrieveAllColumnsInChunks(int chunkSize, byte[] key,
            ColumnParent columnParent, SlicePredicate pred, ConsistencyLevel consistencyLevel)
        {
            pred.Slice_range.Count = chunkSize;
            List<ColumnOrSuperColumn> retColumns = new List<ColumnOrSuperColumn>();

            ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
            while (true)
            {
                object val =
                    cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                    {
                        return client.get_slice(key, columnParent, pred, consistencyLevel);

                    }), KEYSPACE);

                List<ColumnOrSuperColumn> cols = (List<ColumnOrSuperColumn>)val;

                if (pred.Slice_range.Start.Length == 0)
                {
                    //no start specified, beginning of range
                    retColumns.AddRange(cols);
                }
                else
                {
                    //omit the first returned item since it will be the last item
                    //in the previous get
                    for (int i = 1; i < cols.Count; i++)
                    {
                        retColumns.Add(cols[i]);
                    }
                }

                //if we didnt retrieve chunkSize rows, we finished
                if (cols.Count < chunkSize)
                {
                    break;
                }

                //else, we need to set the new start and continue
                if (cols[cols.Count - 1].Column != null)
                {
                    pred.Slice_range.Start = cols[cols.Count - 1].Column.Name;
                }
                else
                {
                    pred.Slice_range.Start = cols[cols.Count - 1].Super_column.Name;
                }
            }

            return retColumns;
        }
Ejemplo n.º 27
0
 public void send_multiget_slice(List<byte[]> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("multiget_slice", TMessageType.Call, seqid_));
     multiget_slice_args args = new multiget_slice_args();
     args.Keys = keys;
     args.Column_parent = column_parent;
     args.Predicate = predicate;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Retrieves the index of all folders owned by this user and attempts to
        /// find and repair any inconsistencies
        /// </summary>
        /// <param name="ownerId"></param>
        /// <returns></returns>
        public void Maint_RepairFolderIndex(UUID ownerId)
        {
            try
            {
                byte[] ownerIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(ownerId.Guid);

                ColumnParent columnParent = new ColumnParent();
                columnParent.Column_family = USERFOLDERS_CF;

                SlicePredicate pred = new SlicePredicate();
                SliceRange range = new SliceRange();
                range.Start = new byte[0];
                range.Finish = new byte[0];
                range.Reversed = false;
                range.Count = int.MaxValue;
                pred.Slice_range = range;


                List<ColumnOrSuperColumn> cols = this.RetrieveAllColumnsInChunks(FOLDER_INDEX_CHUNK_SZ,
                    ownerIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                List<Guid> badIndexFolders = new List<Guid>();

                foreach (ColumnOrSuperColumn col in cols)
                {
                    Dictionary<string, Column> columns = this.IndexColumnsByUTF8Name(col.Super_column.Columns);

                    try
                    {
                        InventoryFolderBase folder = new InventoryFolderBase
                        {
                            ID = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Super_column.Name)),
                            Level = (InventoryFolderBase.FolderLevel)columns["level"].Value[0],
                            Name = ByteEncoderHelper.UTF8Encoder.FromByteArray(columns["name"].Value),
                            Owner = ownerId,
                            ParentID = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(columns["parent_folder"].Value)),
                            Type = (short)ByteEncoderHelper.Int32Encoder.FromByteArray(columns["type"].Value),
                        };
                    }
                    catch (KeyNotFoundException)
                    {
                        //there is a corruption, this folder can not be read
                        badIndexFolders.Add(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Super_column.Name));
                    }
                }

                List<Guid> destroyedFolders = new List<Guid>();
                List<InventoryFolderBase> recoverableFolders = new List<InventoryFolderBase>();

                //for each folder that has a bad index, try to read the folder.
                //if we can read the folder, restore it from the data we have
                //otherwise delete the index, the data is gone
                foreach (Guid id in badIndexFolders)
                {
                    try
                    {
                        InventoryFolderBase folder = this.GetFolderAttributes(new UUID(id));

                        //also verify the parent exists and is readable
                        InventoryFolderBase parentFolder = this.GetFolderAttributes(folder.ParentID);

                        recoverableFolders.Add(folder);
                    }
                    catch (KeyNotFoundException)
                    {
                        destroyedFolders.Add(id);
                    }
                    catch (InventoryObjectMissingException)
                    {
                        destroyedFolders.Add(id);
                    }
                }

                long timeStamp = Util.UnixTimeSinceEpochInMicroseconds();

                foreach (InventoryFolderBase folder in recoverableFolders)
                {
                    //recover anything recoverable
                    this.CreateFolderInternal(folder, timeStamp);
                }

                foreach (Guid id in destroyedFolders)
                {
                    this.RemoveFromIndex(ownerId.Guid, id, timeStamp);
                }
            }
            catch (Exception e)
            {
                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to recover folder index: {0}", e);
                throw new InventoryStorageException(e.Message, e);
            }
        }
Ejemplo n.º 29
0
 public void Read(TProtocol iprot)
 {
     TField field;
     iprot.ReadStructBegin();
     while (true)
     {
       field = iprot.ReadFieldBegin();
       if (field.Type == TType.Stop) {
     break;
       }
       switch (field.ID)
       {
     case 1:
       if (field.Type == TType.List) {
     {
       Keys = new List<byte[]>();
       TList _list87 = iprot.ReadListBegin();
       for( int _i88 = 0; _i88 < _list87.Count; ++_i88)
       {
         byte[] _elem89 = null;
         _elem89 = iprot.ReadBinary();
         Keys.Add(_elem89);
       }
       iprot.ReadListEnd();
     }
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 2:
       if (field.Type == TType.Struct) {
     Column_parent = new ColumnParent();
     Column_parent.Read(iprot);
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 3:
       if (field.Type == TType.Struct) {
     Predicate = new SlicePredicate();
     Predicate.Read(iprot);
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 4:
       if (field.Type == TType.I32) {
     Consistency_level = (ConsistencyLevel)iprot.ReadI32();
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     default:
       TProtocolUtil.Skip(iprot, field.Type);
       break;
       }
       iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Pulls down all folders and collects the list of subfolder
        /// UUIDs for each. Then attempts to read each of the sub folders 
        /// listed in the subfolder index, and removes any indexed subfolders
        /// that are no longer readable due to a partial deletion
        /// </summary>
        /// <param name="ownerId"></param>
        /// <returns></returns>
        public void Maint_RepairSubfolderIndexes(UUID ownerId)
        {
            try
            {
                byte[] ownerIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(ownerId.Guid);

                ColumnParent columnParent = new ColumnParent();
                columnParent.Column_family = USERFOLDERS_CF;

                SlicePredicate pred = new SlicePredicate();
                SliceRange range = new SliceRange();
                range.Start = new byte[0];
                range.Finish = new byte[0];
                range.Reversed = false;
                range.Count = int.MaxValue;
                pred.Slice_range = range;


                List<ColumnOrSuperColumn> cols = this.RetrieveAllColumnsInChunks(FOLDER_INDEX_CHUNK_SZ,
                    ownerIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                List<InventoryFolderBase> goodIndexFolders = new List<InventoryFolderBase>();

                foreach (ColumnOrSuperColumn col in cols)
                {
                    Dictionary<string, Column> columns = this.IndexColumnsByUTF8Name(col.Super_column.Columns);

                    try
                    {
                        InventoryFolderBase folder = new InventoryFolderBase
                        {
                            ID = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Super_column.Name)),
                            Level = (InventoryFolderBase.FolderLevel)columns["level"].Value[0],
                            Name = ByteEncoderHelper.UTF8Encoder.FromByteArray(columns["name"].Value),
                            Owner = ownerId,
                            ParentID = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(columns["parent_folder"].Value)),
                            Type = (short)ByteEncoderHelper.Int32Encoder.FromByteArray(columns["type"].Value),
                        };

                        goodIndexFolders.Add(folder);
                    }
                    catch (KeyNotFoundException)
                    {
                        //there is a corruption, this folder can not be read. Ignore since there is
                        //another maint that can fix this that should be run first.
                    }
                }

                List<KeyValuePair<Guid, Guid>> invalidParentChild = new List<KeyValuePair<Guid, Guid>>();

                //for each folder in the index, retrieve it and check for unreadable subfolders
                foreach (InventoryFolderBase indexFolder in goodIndexFolders)
                {
                    try
                    {
                        InventoryFolderBase folder = this.GetFolder(indexFolder.ID);

                        foreach (var subfolder in folder.SubFolders)
                        {
                            try
                            {
                                InventoryFolderBase subFolderDetails = this.GetFolderAttributes(subfolder.ID);
                            }
                            catch (InventoryObjectMissingException)
                            {
                                invalidParentChild.Add(new KeyValuePair<Guid, Guid>(folder.ID.Guid, subfolder.ID.Guid));
                            }
                            catch (InventoryStorageException e)
                            {
                                if (e.InnerException != null && e.InnerException is KeyNotFoundException)
                                {
                                    invalidParentChild.Add(new KeyValuePair<Guid, Guid>(folder.ID.Guid, subfolder.ID.Guid));
                                }
                            }
                            
                        }
                    }
                    catch (Exception e)
                    {
                        //we can't even get the folder, so no subfolders to fix
                        _log.ErrorFormat("[InWorldz.Data.Inventory.Cassandra] Indexed folder {0} could not be retrieved to look for children: {1}", indexFolder.ID, e);
                    }
                }

                _log.InfoFormat("[InWorldz.Data.Inventory.Cassandra][MAINT] Found {0} subfolder indexes to repair", invalidParentChild.Count);

                long timeStamp = Util.UnixTimeSinceEpochInMicroseconds();

                //we couldn't read the folder, pull it from the subfolder list of its parent
                foreach (KeyValuePair<Guid, Guid> parentChildKvp in invalidParentChild)
                {
                    byte[] childIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(parentChildKvp.Value);
                    Dictionary<byte[], Dictionary<string, List<Mutation>>> muts = new Dictionary<byte[], Dictionary<string, List<Mutation>>>();

                    GenerateSubfolderIndexDeletion(parentChildKvp.Key, timeStamp, childIdBytes, muts);

                    ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
                    cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
                    {
                        client.batch_mutate(muts, DEFAULT_CONSISTENCY_LEVEL);
                        return null;

                    }), KEYSPACE);
                }
            }
            catch (Exception e)
            {
                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to repair subfolder index: {0}", e);
                throw new InventoryStorageException(e.Message, e);
            }
        }
Ejemplo n.º 31
0
 public List<KeySlice> get_indexed_slices(ColumnParent column_parent, IndexClause index_clause, SlicePredicate column_predicate, ConsistencyLevel consistency_level)
 {
     send_get_indexed_slices(column_parent, index_clause, column_predicate, consistency_level);
     return recv_get_indexed_slices();
 }
Ejemplo n.º 32
0
        /// <summary>
        /// Retrieves the index of all folders owned by this user
        /// </summary>
        /// <param name="ownerId"></param>
        /// <returns></returns>
        private Dictionary<Guid, InventoryFolderBase> GetFolderIndex(UUID ownerId)
        {
            try
            {
                byte[] ownerIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(ownerId.Guid);

                ColumnParent columnParent = new ColumnParent();
                columnParent.Column_family = USERFOLDERS_CF;

                SlicePredicate pred = new SlicePredicate();
                SliceRange range = new SliceRange();
                range.Start = new byte[0];
                range.Finish = new byte[0];
                range.Reversed = false;
                range.Count = int.MaxValue;
                pred.Slice_range = range;


                List<ColumnOrSuperColumn> cols = this.RetrieveAllColumnsInChunks(FOLDER_INDEX_CHUNK_SZ,
                    ownerIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);

                Dictionary<Guid, InventoryFolderBase> retIndex = new Dictionary<Guid, InventoryFolderBase>();

                foreach (ColumnOrSuperColumn col in cols)
                {
                    Dictionary<string, Column> columns = this.IndexColumnsByUTF8Name(col.Super_column.Columns);

                    try
                    {
                        InventoryFolderBase folder = new InventoryFolderBase
                        {
                            ID = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Super_column.Name)),
                            Level = (InventoryFolderBase.FolderLevel)columns["level"].Value[0],
                            Name = ByteEncoderHelper.UTF8Encoder.FromByteArray(columns["name"].Value),
                            Owner = ownerId,
                            ParentID = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(columns["parent_folder"].Value)),
                            Type = (short)ByteEncoderHelper.Int32Encoder.FromByteArray(columns["type"].Value),
                        };

                        retIndex.Add(folder.ID.Guid, folder);
                    }
                    catch (KeyNotFoundException)
                    {
                        //there is a corruption, this folder can not be read
                        _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra]: Unable to read all columns from folder index item: {0}",
                            new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Super_column.Name)).ToString());
                    }
                }

                return retIndex;
            }
            catch (Exception e)
            {
                _log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to retrieve folder index: {0}", e);
                throw new InventoryStorageException(e.Message, e);
            }
        }