Exemple #1
0
        static void Main(string[] args)
        {
            //�������ݿ�����
            TTransport transport = new TSocket("192.168.10.2", 9160);
            TProtocol protocol = new TBinaryProtocol(transport);
            Cassandra.Client client = new Cassandra.Client(protocol);
            transport.Open();

            System.Text.Encoding utf8Encoding = System.Text.Encoding.UTF8;
            long timeStamp = DateTime.Now.Millisecond;
            ColumnPath nameColumnPath = new ColumnPath()
            {
                Column_family = "Standard1",
                Column = utf8Encoding.GetBytes("age")
            };
            //�����
            client.insert("Keyspace1",
                          "studentA",
                          nameColumnPath,
                          utf8Encoding.GetBytes("18"),
                          timeStamp,
                          ConsistencyLevel.ONE);

               //��ȡ����
            ColumnOrSuperColumn returnedColumn = client.get("Keyspace1", "studentA", nameColumnPath, ConsistencyLevel.ONE);
            Console.WriteLine("Keyspace1/Standard1: age: {0}, value: {1}", utf8Encoding.GetString(returnedColumn.Column.Name), utf8Encoding.GetString(returnedColumn.Column.Value));

               //�ر�����
               transport.Close();
        }
Exemple #2
0
 public ColumnOrSuperColumn get(string keyspace, string key, ColumnPath column_path, ConsistencyLevel consistency_level)
 {
     send_get(keyspace, key, column_path, consistency_level);
     return recv_get();
 }
 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) {
     Path = new ColumnPath();
     Path.Read(iprot);
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 3:
       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();
 }
 public void send_remove(byte[] key, ColumnPath column_path, long timestamp, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("remove", TMessageType.Call, seqid_));
     remove_args args = new remove_args();
     args.Key = key;
     args.Column_path = column_path;
     args.Timestamp = timestamp;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
 public void remove_counter(byte[] key, ColumnPath path, ConsistencyLevel consistency_level)
 {
     send_remove_counter(key, path, consistency_level);
     recv_remove_counter();
 }
        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
            }
        }
Exemple #7
0
 public void send_get(byte[] key, ColumnPath column_path, ConsistencyLevel consistency_level)
 #endif
 {
   oprot_.WriteMessageBegin(new TMessage("get", TMessageType.Call, seqid_));
   get_args args = new get_args();
   args.Key = key;
   args.Column_path = column_path;
   args.Consistency_level = consistency_level;
   args.Write(oprot_);
   oprot_.WriteMessageEnd();
   #if SILVERLIGHT
   return oprot_.Transport.BeginFlush(callback, state);
   #else
   oprot_.Transport.Flush();
   #endif
 }
Exemple #8
0
      /// <summary>
      /// Get the Column or SuperColumn at the given column_path. If no value is present, NotFoundException is thrown. (This is
      /// the only method that can throw an exception under non-failure conditions.)
      /// </summary>
      /// <param name="key"></param>
      /// <param name="column_path"></param>
      /// <param name="consistency_level"></param>
      public ColumnOrSuperColumn get(byte[] key, ColumnPath column_path, ConsistencyLevel consistency_level)
      {
        #if !SILVERLIGHT
        send_get(key, column_path, consistency_level);
        return recv_get();

        #else
        var asyncResult = Begin_get(null, null, key, column_path, consistency_level);
        return End_get(asyncResult);

        #endif
      }
Exemple #9
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) {
     this.keyspace = iprot.ReadString();
     this.__isset.keyspace = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 2:
       if (field.Type == TType.String) {
     this.key = iprot.ReadString();
     this.__isset.key = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 3:
       if (field.Type == TType.Struct) {
     this.column_path = new ColumnPath();
     this.column_path.Read(iprot);
     this.__isset.column_path = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 4:
       if (field.Type == TType.I64) {
     this.timestamp = iprot.ReadI64();
     this.__isset.timestamp = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 5:
       if (field.Type == TType.I32) {
     this.consistency_level = (ConsistencyLevel)iprot.ReadI32();
     this.__isset.consistency_level = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     default:
       TProtocolUtil.Skip(iprot, field.Type);
       break;
       }
       iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }
Exemple #10
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) {
     this.keyspace = iprot.ReadString();
     this.__isset.keyspace = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 2:
       if (field.Type == TType.List) {
     {
       this.keys = new List<string>();
       TList _list25 = iprot.ReadListBegin();
       for( int _i26 = 0; _i26 < _list25.Count; ++_i26)
       {
         string _elem27 = null;
         _elem27 = iprot.ReadString();
         this.keys.Add(_elem27);
       }
       iprot.ReadListEnd();
     }
     this.__isset.keys = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 3:
       if (field.Type == TType.Struct) {
     this.column_path = new ColumnPath();
     this.column_path.Read(iprot);
     this.__isset.column_path = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     case 4:
       if (field.Type == TType.I32) {
     this.consistency_level = (ConsistencyLevel)iprot.ReadI32();
     this.__isset.consistency_level = true;
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     default:
       TProtocolUtil.Skip(iprot, field.Type);
       break;
       }
       iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }
Exemple #11
0
 public void send_multiget(string keyspace, List<string> keys, ColumnPath column_path, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("multiget", TMessageType.Call, seqid_));
     multiget_args args = new multiget_args();
     args.Keyspace = keyspace;
     args.Keys = keys;
     args.Column_path = column_path;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
Exemple #12
0
 public void send_insert(string keyspace, string key, ColumnPath column_path, byte[] value, long timestamp, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("insert", TMessageType.Call, seqid_));
     insert_args args = new insert_args();
     args.Keyspace = keyspace;
     args.Key = key;
     args.Column_path = column_path;
     args.Value = value;
     args.Timestamp = timestamp;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
Exemple #13
0
 public void remove(string keyspace, string key, ColumnPath column_path, long timestamp, ConsistencyLevel consistency_level)
 {
     send_remove(keyspace, key, column_path, timestamp, consistency_level);
     recv_remove();
 }
Exemple #14
0
 public Dictionary<string, ColumnOrSuperColumn> multiget(string keyspace, List<string> keys, ColumnPath column_path, ConsistencyLevel consistency_level)
 {
     send_multiget(keyspace, keys, column_path, consistency_level);
     return recv_multiget();
 }
Exemple #15
0
 public void insert(string keyspace, string key, ColumnPath column_path, byte[] value, long timestamp, ConsistencyLevel consistency_level)
 {
     send_insert(keyspace, key, column_path, value, timestamp, consistency_level);
     recv_insert();
 }
Exemple #16
0
 public IAsyncResult send_remove_counter(AsyncCallback callback, object state, byte[] key, ColumnPath path, ConsistencyLevel consistency_level)
Exemple #17
0
 public IAsyncResult Begin_get(AsyncCallback callback, object state, byte[] key, ColumnPath column_path, ConsistencyLevel consistency_level)
 {
   return send_get(callback, state, key, column_path, consistency_level);
 }
Exemple #18
0
        public ColumnOrSuperColumn GetColumn(string family, string key, string superColumnName, string columnName)
        {
            //var getCommand = new GetCommand
            //                     {
            //                         KeySpace = Name,
            //                         Key = key,
            //                         ColumnFamily = family,
            //                         ColumnName = columnName,
            //                         SuperColumnName = superColumnName
            //                     };
            //using (var connection = AquilesHelper.RetrieveConnection(Cluster))
            //{
            //    connection.Execute(getCommand);
            //    return getCommand.Output == null ? null : getCommand.Output.Column;
            //}

            byte[] keyAsByteArray = Encoding.ASCII.GetBytes(key);
            byte[] columnNameAsByteArray = Encoding.ASCII.GetBytes(columnName);
            var columnPath = new ColumnPath
                                        {
                Column = columnNameAsByteArray,
                Column_family = family,
            };

            ICluster cluster = AquilesHelper.RetrieveCluster(Cluster);

            return (ColumnOrSuperColumn) cluster.Execute(new ExecutionBlock(client =>
                                                                                {
                                                                                    try
                                                                                    {
                                                                                        return client.get(keyAsByteArray, columnPath,
                                                                                                          ConsistencyLevel.ONE);
                                                                                    }
                                                                                    catch (Exception e)
                                                                                    {

                                                                                        return null;
                                                                                    }
                                                                                }), keyspaceName);
        }
Exemple #19
0
 public IAsyncResult send_get(AsyncCallback callback, object state, byte[] key, ColumnPath column_path, ConsistencyLevel consistency_level)
        public bool Search(string msg)
        {
            #region Unused code
            /*var doc = XDocument.Load(@"D:\\Search.xml");
            foreach (var child in doc.Descendants("cloudMessage"))
            {
                if (child.Value == msg)
                    return true;
            }
            return false;
             */
            #endregion

            byte[] key = ByteEncoderHelper.UTF8Encoder.ToByteArray(msg);
            //byte[] extension = ByteEncoderHelper.UTF8Encoder.ToByteArray("pdf");
            //byte[] size = ByteEncoderHelper.UTF8Encoder.ToByteArray("194329423");

            // Fetch inserted data
            ColumnPath columnPath = new ColumnPath()
            {
                Column = ByteEncoderHelper.UTF8Encoder.ToByteArray("url"),
                Column_family = "resource",
            };

            ColumnOrSuperColumn columnOrSuperColumn = null;

            #region Unused code
            /*
            ColumnParent columnParent = new ColumnParent();
            Column urlColumn = new Column()
            {
                Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("url"),
                Timestamp = UnixHelper.UnixTimestamp,
                Value = key
            };

            Column extensionColumn = new Column()
            {
                Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("extension"),
                Timestamp = UnixHelper.UnixTimestamp,
                Value = extension
            };

            Column sizeColumn = new Column()
            {
                Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("size"),
                Timestamp = UnixHelper.UnixTimestamp,
                Value = size
            };

            columnParent.Column_family = "resource";

            cluster.Execute(new ExecutionBlock(delegate(CassandraClient client)
            {
                client.insert(key, columnParent, urlColumn, ConsistencyLevel.ONE);
                client.insert(key, columnParent, extensionColumn, ConsistencyLevel.ONE);
                client.insert(key, columnParent, sizeColumn, ConsistencyLevel.ONE);

                return null;
            }), KEYSPACENAME);
            */

            #endregion

            try
            {
                ICluster cluster = Aquiles.Cassandra10.AquilesHelper.RetrieveCluster("Test Cluster");
                cluster.Execute(new ExecutionBlock(delegate(CassandraClient client)
                {
                    columnOrSuperColumn = client.get(key, columnPath, ConsistencyLevel.ONE);
                    return columnOrSuperColumn;
                }), KEYSPACENAME);

                if (columnOrSuperColumn.Column.Value.SequenceEqual<byte>(key))
                    return true;
            }
            catch (Exception ex)
            {
                return false;
            }

            return false;
        }
        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);
            }
        }
Exemple #22
0
 public IAsyncResult Begin_remove(AsyncCallback callback, object state, byte[] key, ColumnPath column_path, long timestamp, ConsistencyLevel consistency_level)
 {
   return send_remove(callback, state, key, column_path, timestamp, consistency_level);
 }
 public void remove(byte[] key, ColumnPath column_path, long timestamp, ConsistencyLevel consistency_level)
 {
     send_remove(key, column_path, timestamp, consistency_level);
     recv_remove();
 }
Exemple #24
0
      /// <summary>
      /// Remove data from the row specified by key at the granularity specified by column_path, and the given timestamp. Note
      /// that all the values in column_path besides column_path.column_family are truly optional: you can remove the entire
      /// row by just specifying the ColumnFamily, or you can remove a SuperColumn or a single Column by specifying those levels too.
      /// </summary>
      /// <param name="key"></param>
      /// <param name="column_path"></param>
      /// <param name="timestamp"></param>
      /// <param name="consistency_level"></param>
      public void remove(byte[] key, ColumnPath column_path, long timestamp, ConsistencyLevel consistency_level)
      {
        #if !SILVERLIGHT
        send_remove(key, column_path, timestamp, consistency_level);
        recv_remove();

        #else
        var asyncResult = Begin_remove(null, null, key, column_path, timestamp, consistency_level);
        End_remove(asyncResult);

        #endif
      }
 public void send_get(byte[] key, ColumnPath column_path, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("get", TMessageType.Call, seqid_));
     get_args args = new get_args();
     args.Key = key;
     args.Column_path = column_path;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
Exemple #26
0
 public IAsyncResult send_remove(AsyncCallback callback, object state, byte[] key, ColumnPath column_path, long timestamp, ConsistencyLevel consistency_level)
 public void send_remove_counter(byte[] key, ColumnPath path, ConsistencyLevel consistency_level)
 {
     oprot_.WriteMessageBegin(new TMessage("remove_counter", TMessageType.Call, seqid_));
     remove_counter_args args = new remove_counter_args();
     args.Key = key;
     args.Path = path;
     args.Consistency_level = consistency_level;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }
Exemple #28
0
 public IAsyncResult Begin_remove_counter(AsyncCallback callback, object state, byte[] key, ColumnPath path, ConsistencyLevel consistency_level)
 {
   return send_remove_counter(callback, state, key, path, consistency_level);
 }
 public ColumnOrSuperColumn get(byte[] key, ColumnPath column_path, ConsistencyLevel consistency_level)
 {
     send_get(key, column_path, consistency_level);
     return recv_get();
 }
Exemple #30
0
      /// <summary>
      /// Remove a counter at the specified location.
      /// Note that counters have limited support for deletes: if you remove a counter, you must wait to issue any following update
      /// until the delete has reached all the nodes and all of them have been fully compacted.
      /// </summary>
      /// <param name="key"></param>
      /// <param name="path"></param>
      /// <param name="consistency_level"></param>
      public void remove_counter(byte[] key, ColumnPath path, ConsistencyLevel consistency_level)
      {
        #if !SILVERLIGHT
        send_remove_counter(key, path, consistency_level);
        recv_remove_counter();

        #else
        var asyncResult = Begin_remove_counter(null, null, key, path, consistency_level);
        End_remove_counter(asyncResult);

        #endif
      }