【问题标题】:scribe with protocol buffer and advanced thrift?带有协议缓冲区和高级节俭的抄写员?
【发布时间】:2010-01-21 01:31:33
【问题描述】:

我有两个问题:

问题一:

--thrift 可以提供内部类功能吗? (接下来看我的例子)

-- 如果可以,thrift 是否可以轻松使用此类功能?

这里是 scribe 界面 (scribe/if/scribe.thrift)。但是它的message字段只能是字符串,我认为不够灵活。

#!/usr/local/bin/thrift --cpp --php

##  Copyright (c) 2007-2008 Facebook
...
...
## See accompanying file LICENSE or visit the Scribe site at:
## http://developers.facebook.com/scribe/

include "fb303/if/fb303.thrift"

namespace cpp scribe.thrift

enum ResultCode
{
  OK,
  TRY_LATER
}

struct LogEntry
{
  1:  string category,
  2:  string message
}

service scribe extends fb303.FacebookService
{
  ResultCode Log(1: list<LogEntry> messages);
}

如果我能做到以下事情那就太好了(我什至不知道 thrift 本身是否根据其文档提供了内部类功能——但协议缓冲区肯定可以)。

enum ResultCode
{
  OK,
  TRY_LATER
}

struct MyLogStructure {
  1: string field_name;
  2: string value;
}

struct LogEntry
{
  1:  string category,
  2:  MyLogStructure message
}

service scribe extends fb303.FacebookService
{
  ResultCode Log(1: list<LogEntry> messages);
}

问题 2:

-- scribe 可以轻松地使用协议缓冲区作为内部数据表示吗? (无需过多修改代码)

-- 如果上述问题的答案是“否”,Google 是否开源了它的 sribe 实现?

【问题讨论】:

    标签: logging protocol-buffers thrift scribe-server


    【解决方案1】:

    是的,Thrift 结构可以包含其他结构,并且您的定义(以下重复)将起作用:

    enum ResultCode { OK, TRY_LATER }
    
    struct MyLogStructure {
      1: string field_name;
      2: string value;
    }
    
    struct LogEntry {
      1: string category,
      2: MyLogStructure message 
    }
    
    service scribe extends fb303.FacebookService {
      ResultCode Log(1: list messages);
    }
    

    如果您像这样重新定义 Scribe 的接口,您可能必须修改 Scribe 的代码来处理您的新类型,具体取决于它在内部对 string message 所做的事情。

    当然,您总是可以将您的 MyLogStructure 对象序列化为字符串,从而完全避免这个问题。

    不,我不认为 Scribe 能够轻松地使用协议缓冲区作为其内部数据表示。所有的 RPC 代码都是从这些定义中生成的,你可以重新定义 Log 方法来获取任意对象(比如,让它成为一个 Protocol Buffers 对象),但这和上面的一样难。

    据我所知,Google 尚未开源任何分布式日志系统。来自 Yahoo/Hadoop 的 Chukwa 是另一种选择。

    【讨论】:

      猜你喜欢
      • 2011-05-16
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-15
      • 1970-01-01
      • 2014-03-18
      相关资源
      最近更新 更多