Thrift.Transport.TTransportException:无法写入空输出流

发布于 2024-08-25 00:49:49 字数 3105 浏览 10 评论 0原文

我正在使用 Cassandra 和 Thrift 库进行一些工作。我意识到这些都是非常早期的库,并且(毫无疑问)会在某个时候发生变化。

我一直在使用以下链接来获取设置我的 C# 的帮助用于向我的 Cassandra 服务器(我在本地 VirtualBox 的 Ubuntu Server 实例中运行)写入和读取的代码。我已经确认简单的读/写功能可以工作。

我遇到问题的地方是执行以下方法(该方法是使用 Cassandra 附带的 thrift.definition 文件为我生成的):

public void send_get_count(string keyspace, string key, ColumnParent column_parent, ConsistencyLevel consistency_level)

这是我的设置代码:

TTransport _transport;
TProtocol _protocol;
Cassandra.Client _client;

public Test()
{
    _transport = new TSocket("192.168.56.101", 9160);
    _protocol = new TBinaryProtocol(_transport);
    _client = new Cassandra.Client(_protocol);
}

我的调用代码如下所示:

public void GetAllBlogEntries()
    {
        var timestamp = DateTime.Now.Millisecond;
        var keyspace = "Keyspace1";

        var utf8Encoding = System.Text.Encoding.UTF8;

        var columnParent = new ColumnParent() {Column_family = "BlogEntries"};
        var predicate = new SlicePredicate()
        {
            Slice_range = new SliceRange()
                          {
                              Start = new byte[0],
                              Finish = new byte[0],
                              Count = 10,
                              Reversed = false
                          }
        };

        var results = _client.get_range_slice(keyspace, columnParent, predicate, "", "", 5, ConsistencyLevel.ONE);

        foreach(var slice in results)
        {
            Console.WriteLine("Found Key: {0}", slice.Key);
            foreach(var resultColumn in slice.Columns)
            {
                var column = resultColumn.Column;
                Console.WriteLine("\tName: {0}, value: {1}",
                                  utf8Encoding.GetString(column.Name),
                                  utf8Encoding.GetString(column.Value));                        
            }
        }
    } 

该方法的第一行是我收到异常:

oprot_.WriteMessageBegin(new TMessage("get_count", TMessageType.Call, seqid_));

这是异常:

Thrift.Transport.TTransportException:无法写入空输出流 在 Thrift.Transport.TStreamTransport.Write(Byte[] buf, Int32 off, Int32 len) 在 Thrift.Protocol.TBinaryProtocol.WriteI32(Int32 i32) 在 Thrift.Protocol.TBinaryProtocol.WriteMessageBegin(TMessage 消息) 在 Cassandra.cs 中的 Apache.Cassandra.Cassandra.Client.send_get_range_slice(String keyspace, ColumnParent column_parent, SlicePredicate predicate, String start_key, String finish_key, Int32 row_count, ConsistencyLevelconsistency_level) 处:第 341 行 在 Cassandra.cs 中的 Apache.Cassandra.Cassandra.Client.get_range_slice(String keyspace, ColumnParent column_parent, SlicePredicate predicate, String start_key, String finish_key, Int32 row_count, ConsistencyLevel Consistency_level) 处:第 335 行 在 Test.cs 中的 CassandraDemo.Models.Test.GetAllBlogEntries() 处:第 212 行 在 TestTest.cs 中的 CassandraDemo.Tests.Models.TestTest.Test_GetAllBlogEntries_Success() 处:第 42 行

有什么想法吗?

I'm doing some work with Cassandra and the Thrift libraries. I realize these are very early libraries and will (undoubtedly) change at some point.

I've been using the following link for help with setting up my C# code to write and read to and from my Cassandra server (which I have running in an Ubuntu Server instance in my local VirtualBox). I've confirmed that the trivial read / write functionality works.

Where I'm having a problem is executing the following method (which was generated for me using the thrift.definition file that came with Cassandra):

public void send_get_count(string keyspace, string key, ColumnParent column_parent, ConsistencyLevel consistency_level)

Here's my setup code:

TTransport _transport;
TProtocol _protocol;
Cassandra.Client _client;

public Test()
{
    _transport = new TSocket("192.168.56.101", 9160);
    _protocol = new TBinaryProtocol(_transport);
    _client = new Cassandra.Client(_protocol);
}

My calling code looks like so:

public void GetAllBlogEntries()
    {
        var timestamp = DateTime.Now.Millisecond;
        var keyspace = "Keyspace1";

        var utf8Encoding = System.Text.Encoding.UTF8;

        var columnParent = new ColumnParent() {Column_family = "BlogEntries"};
        var predicate = new SlicePredicate()
        {
            Slice_range = new SliceRange()
                          {
                              Start = new byte[0],
                              Finish = new byte[0],
                              Count = 10,
                              Reversed = false
                          }
        };

        var results = _client.get_range_slice(keyspace, columnParent, predicate, "", "", 5, ConsistencyLevel.ONE);

        foreach(var slice in results)
        {
            Console.WriteLine("Found Key: {0}", slice.Key);
            foreach(var resultColumn in slice.Columns)
            {
                var column = resultColumn.Column;
                Console.WriteLine("\tName: {0}, value: {1}",
                                  utf8Encoding.GetString(column.Name),
                                  utf8Encoding.GetString(column.Value));                        
            }
        }
    } 

The first line of this method is where I am getting my exception:

oprot_.WriteMessageBegin(new TMessage("get_count", TMessageType.Call, seqid_));

And here is the exception:

Thrift.Transport.TTransportException: Cannot write to null outputstream
at Thrift.Transport.TStreamTransport.Write(Byte[] buf, Int32 off, Int32 len)
at Thrift.Protocol.TBinaryProtocol.WriteI32(Int32 i32)
at Thrift.Protocol.TBinaryProtocol.WriteMessageBegin(TMessage message)
at Apache.Cassandra.Cassandra.Client.send_get_range_slice(String keyspace, ColumnParent column_parent, SlicePredicate predicate, String start_key, String finish_key, Int32 row_count, ConsistencyLevel consistency_level) in Cassandra.cs: line 341
at Apache.Cassandra.Cassandra.Client.get_range_slice(String keyspace, ColumnParent column_parent, SlicePredicate predicate, String start_key, String finish_key, Int32 row_count, ConsistencyLevel consistency_level) in Cassandra.cs: line 335
at CassandraDemo.Models.Test.GetAllBlogEntries() in Test.cs: line 212
at CassandraDemo.Tests.Models.TestTest.Test_GetAllBlogEntries_Success() in TestTest.cs: line 42

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2024-09-01 00:49:49

您需要在传输上调用 Open()。

You need to call Open() on the transport.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文