gRPC error code

RPC.response.status.code HTTP RPC Description 0 - OK 200 OK Not an error; returned on success. 1 - CANCELLED 499 Client Closed Request The operation was cancelled, typically by the caller. 2 - UNKNOWN 500 Internal Server Error Unknown error. For example, this error may be returned when a Status value received from another address space belongs to an error space that is not known in this address space. Also errors raised by APIs that do not return enough error information may be converted to this error. 3 - INVALID_ARGUMENT 400 Bad Request The client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the system (e.g., a malformed file name). 4 - DEADLINE_EXCEEDED 504 Gateway Timeout The deadline expired before the operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. 5 - NOT_FOUND 404 Not Found Some requested entity (e.g., file or directory) was not found.Note to server developers: if a request is denied for an entire class of users, such as gradual feature rollout or undocumented whitelist,NOT_FOUND may be used. If a request is denied for some users within a class of users, such as user-based access control, PERMISSION_DENIED must be used. 6 - ALREADY_EXISTS 409 Conflict The entity that a client attempted to create (e.g., file or directory) already exists. 7 - PERMISSION_DENIED 403 Forbidden The caller does not have permission to execute the specified operation. PERMISSION_DENIED must not be used for rejections caused by exhausting some resource (use RESOURCE_EXHAUSTED instead for those errors). PERMISSION_DENIED must not be used if the caller can not be identified (use UNAUTHENTICATED instead for those errors). This error code does not imply the request is valid or the requested entity exists or satisfies other pre-conditions. 8 - RESOURCE_EXHAUSTED 429 Too Many Requests Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. 9 - FAILED_PRECONDITION 400 Bad Request The operation was rejected because the system is not in a state required for the operation’s execution. For example, the directory to be deleted is non-empty, an rmdir operation is applied to a non-directory, etc.Service implementors can use the following guidelines to decide between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: (a) Use UNAVAILABLE if the client can retry just the failing call. (b) Use ABORTED if the client should retry at a higher level (e.g., when a client-specified test-and-set fails, indicating the client should restart a read-modify-write sequence). (c) Use FAILED_PRECONDITION if the client should not retry until the system state has been explicitly fixed. E.g., if an “rmdir” fails because the directory is non-empty, FAILED_PRECONDITION should be returned since the client should not retry unless the files are deleted from the directory. 10 - ABORTED 409 Conflict The operation was aborted, typically due to a concurrency issue such as a sequencer check failure or transaction abort.See the guidelines above for deciding between FAILED_PRECONDITION,ABORTED, and UNAVAILABLE. 11 - OUT_OF_RANGE 400 Bad Request The operation was attempted past the valid range. E.g., seeking or reading past end-of-file.Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state changes. For example, a 32-bit file system will generate INVALID_ARGUMENT if asked to read at an offset that is not in the range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to read from an offset past the current file size.There is a fair bit of overlap between FAILED_PRECONDITION and OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error) when it applies so that callers who are iterating through a space can easily look for an OUT_OF_RANGE error to detect when they are done. 12 - UNIMPLEMENTED 501 Not Implemented The operation is not implemented or is not supported/enabled in this service. 13 - INTERNAL 500 Internal Server Error Internal errors. This means that some invariants expected by the underlying system have been broken. This error code is reserved for serious errors. 14 - UNAVAILABLE 503 Service Unavailable The service is currently unavailable. This is most likely a transient condition, which can be corrected by retrying with a backoff.See the guidelines above for deciding between FAILED_PRECONDITION,ABORTED, and UNAVAILABLE. 15 - DATA_LOSS 500 Internal Server Error Unrecoverable data loss or corruption. 16 - UNAUTHENTICATED 401 Unauthorized The request does not have valid authentication credentials for the peration.

2019-06-12 · 4 min · L

Protobuf 总结

Protobuf 是什么 Protobuf 是一种平台无关、语言无关、可扩展且轻便高效的序列化数据结构的协议,可以用于通信协议和数据存储等。 传输协议 - 如 json、XML IDL - 接口描述语言 存储格式 - 序列化压缩后存储到数据库 核心竞争力 向前向后兼容性 - 新老版本兼容,无需考虑版本升级 多语言代码生成 - 支持 Java、Python、PHP、Go 等编程语言 快&小 - 序列化、反序列化速度快,压缩比优秀 关键技术 varints 编码 每个字节使用其中 7 位保存数字,最高位表示后面是否还有内容 低位在前,高位在后 保留了fixed32和fixed64,用于传递大的正数 int32、int64、unit32、uint64、bool,序列化结果相互兼容,可以修改 zigzag 编码 传统上,负数最高位为 1,小负数会浪费编码长度 (n<<1)^(n>>31) -1 将会被编码成 1,1 将会编码成 2,-2 将会被编码成 3 sint32和sint64使用 zigzag 编码 message structure 编码 Tag-Value 编码 Tag=(field_number<<3)|wire_type->varints wire_type:0 表示 varints,1 表示固定 64 位,5 表示固定 32 位 wire_type:2 表示 Tag-Length-Value 编码(TLV),Length 使用 varints string、bytes、message 嵌套,都采用 TLV 编码 wire_type 只有 0、1、2、5,那么 3 和 4 去哪了?—被废除了 ...

2019-03-14 · 1 min · L

Learning go from zero to hero - Part 2

作者:Milap Neupane 链接:https://medium.freecodecamp.org/learning-go-from-zero-to-hero-d2a3223b3d86 函数 main.go包中定义的func main()是执行程序的入口。可以定义和使用更多函数。让我们看一个简单的例子: func add(a int, b int) int { c := a + b return c } func main() { fmt.Println(add(2, 1)) } // 3 正如我们在上面的例子中所看到的,使用**func关键字后跟函数名来定义 Go 函数。函数所需的参数**需要根据其数据类型定义,最后是返回的数据类型。 函数的返回也可以在函数中预定义: func add(a int, b int) (c int) { c = a + b return } func main() { fmt.Println(add(2, 1)) } // 3 这里 c 被定义为返回变量。因此,定义的变量 c 将自动返回,而无需在结尾的 return 语句中定义。 还可以从单个函数返回多个返回值,将返回值与逗号分隔开。 func add(a int, b int) (int, string) { c := a + b return c, "successfully added" } func main() { sum, message := add(2, 1) fmt.Println(message) fmt.Println(sum) } 结构、方法和接口 Go 不是一个完全面向对象的语言,但是它的结构,接口和方法,和面向对象有异曲同工之妙。 结构 结构struct是不同类型字段的集合。结构用于将数据分组在一起。例如,如果我们想要对Person类型的数据进行分组,我们会定义一个人的属性,其中可能包括姓名,年龄,性别。可以使用以下语法定义结构: type person struct { name string age int gender string } 在定义了人类型结构的情况下,现在让我们创建一个person: //方式 1:指定属性和值 p = person{name: "Bob", age: 42, gender: "Male"} //方式 2:仅指定值 person{"Bob", 42, "Male"} 我们可以用点.轻松访问这些数据 ...

2018-12-28 · 5 min · L

Learning go from zero to hero - Part 1

作者:Milap Neupane 链接:https://medium.freecodecamp.org/learning-go-from-zero-to-hero-d2a3223b3d86 开始 想到刚开始学习 Go 的时候,也是不清不楚地本着拿来能用就行的心态,没有系统学习,导致学习过程中踩坑无数。今天发现一篇文章写的很好,Go 语言的特征讲得很细,翻译给需要的初学 Go 的同学。 前言 让我们从 Go(或者称为 Golang)的一个小介绍开始。Go 由 Google 工程师 Robert Griesemer,Rob Pike 和 Ken Thompson 设计。它是一种静态类型的编译语言。第一个版本于 2012 年 3 月作为开源发布。 “Go 是一种开源编程语言,可以轻松构建简单,可靠,高效的软件” 在许多语言中,有许多方法可以解决给定的问题。程序员可以花很多时间思考解决问题的最佳方法。 另一方面,Go 相信更少的功能 — 只有一种正确的方法来解决问题。 这节省了开发人员的时间,并使大型代码库易于维护。 “功能越多,成本越高” — Rob Pike 入门 Go 由package组成。名为main的包告诉 Go 编译器被编译为可执行文件,而不是作为 library 被引用。它是应用程序的主入口。主包定义为: package main 让我们在 Go 工作区中创建一个简单的 hello world 示例。 工作区 Go 中的工作空间由环境变量定义,称为 GOPATH。 你的任何代码都将写在工作区内。Go 将搜索GOPATH目录中的任何包,或者GOROOT在安装 Go 时默认设置的目录。注:GOROOT 是安装 go 的路径。 ...

2018-12-22 · 3 min · L