dropbox1111 2015-04-24 14:55
浏览 36
已采纳

AppEngine IO复制问题导致“ API错误10(文件:FILE_NOT_OPENED)”

My GoLang AppEngine code is uncompressing a ZIP file and then saving off each file as BlobStore content. I've seen it take over 30 seconds to save the data and then it fails with "API error 10 (file: FILE_NOT_OPENED)." The size of the uncompressed file being written is about 1.5 megabytes. Here is the code that does the copy to a new BlogStore item from the Zip reader:

func storeBlob(c appengine.Context, rc io.Reader, mimeType string) (appengine.BlobKey, error) {

c.Infof("Creating new blob of type: [%v]", mimeType)
var key appengine.BlobKey
w, err := blobstore.Create(c, mimeType)
if err != nil {
    return "", err
}

c.Infof("Copying blob data")
_, err = io.Copy(w, rc)
if err != nil {
    return "", err
}

c.Infof("Closing Blob")
err = w.Close()
if err != nil {
    return "", err
}

c.Infof("Getting Blob Key")
key, err = w.Key()
if err != nil {
    return "", err
}
return key, nil

}

The production appengine server locks up for 30 seconds and then reports the error on the io.Copy call. Any thoughts on how to troubleshoot this?

  • 写回答

1条回答 默认 最新

  • dongpalou5352 2015-05-01 03:12
    关注

    This error is because your request is timing out. Create makes a protocol buffer request that looks like this:

    oreq := &filepb.OpenRequest{
        Filename:      res.Filename,
        ContentType:   filepb.FileContentType_RAW.Enum(),
        OpenMode:      filepb.OpenRequest_APPEND.Enum(),
        ExclusiveLock: proto.Bool(true),
    }
    

    The corresponding definition:

    type OpenRequest struct {
        Filename             *string                      `protobuf:"bytes,1,req,name=filename" json:"filename,omitempty"`
        ContentType          *FileContentType_ContentType `protobuf:"varint,2,req,name=content_type,enum=files.FileContentType_ContentType" json:"content_type,omitempty"`
        OpenMode             *OpenRequest_OpenMode        `protobuf:"varint,3,req,name=open_mode,enum=files.OpenRequest_OpenMode" json:"open_mode,omitempty"`
        ExclusiveLock        *bool                        `protobuf:"varint,4,opt,name=exclusive_lock,def=0" json:"exclusive_lock,omitempty"`
        BufferedOutput       *bool                        `protobuf:"varint,5,opt,name=buffered_output,def=0" json:"buffered_output,omitempty"`
        OpenLeaseTimeSeconds *int32                       `protobuf:"varint,6,opt,name=open_lease_time_seconds,def=30" json:"open_lease_time_seconds,omitempty"`
        XXX_unrecognized     []byte                       `json:"-"`
    }
    

    Notice OpenLeaseTimeSeconds is unset. It will default to 30 seconds:

    const Default_OpenRequest_OpenLeaseTimeSeconds int32 = 30
    

    So it's probably closing the connection underneath you.

    You have two options:

    1. Write your own Create method which sets the lease time to something greater than 30 seconds. The most you can do is 60 seconds since then your request will be killed, in which case you will need to use a Task Queue.

    2. The API is deprecated:

      Warning: The Files API feature used here to write files to Blobstore has been deprecated and is going to be removed at some time in the future, in favor of writing files to Google Cloud Storage and using Blobstore to serve them. For more information, please visit Google Cloud Storage.

      So maybe you should try google storage instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。