How to use memcache in dataflow?

前端 未结 1 467
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 06:50

I would like to use Memcache in dafalow ParDo? any ideas how?I can\'t use existing memcahse lib as they belong to appengine and are not serializable. Rohit

相关标签:
1条回答
  • 2021-01-15 07:17

    My guess is, you have a private variable in your DoFn of type MemcacheServiceImpl (if my guess is wrong, please edit your question to include the code of your DoFn).

    Indeed, Dataflow serializes your DoFn's when you submit the pipeline and de-serializes them on the workers. The proper way to handle this is to make the variable transient, and initialize it lazily:

    class MyDoFn extends DoFn<..., ...> {
      private transient MemcacheService memcache;
      private MemcacheService getMemcache() {
        if (memcache == null) {
          memcache = MemcacheServiceFactory.getMemcacheService();
          ...
        }
      }
    
      public void process(...) {
        ...use getMemcache()...
      }
    }
    

    Also note that to access AppEngine APIs, including Memcache, from a non-AppEngine environment, you should use the Remote API.

    0 讨论(0)
提交回复
热议问题