/*static*/ mutation_ptr mutation::read_from(binary_reader& reader, dsn_message_t from) { mutation_ptr mu(new mutation()); unmarshall(reader, mu->data, DSF_THRIFT_BINARY); for (const mutation_update& update : mu->data.updates) { dassert(update.code != TASK_CODE_INVALID, "invalid mutation task code"); } mu->client_requests.resize(mu->data.updates.size()); if (nullptr != from) { mu->_prepare_request = from; dsn_msg_add_ref(from); // released on dctor } snprintf_p(mu->_name, sizeof(mu->_name), "%" PRId32 ".%" PRId32 ".%" PRId64 ".%" PRId64, mu->data.header.pid.get_app_id(), mu->data.header.pid.get_partition_index(), mu->data.header.ballot, mu->data.header.decree); return mu; }
DSN_API const char* dsn_address_to_string(dsn_address_t addr) { char* p = dsn::tls_dsn.scratch_next(); auto sz = sizeof(dsn::tls_dsn.scratch_buffer[0]); struct in_addr net_addr; # ifdef _WIN32 char* ip_str; # else int ip_len; # endif switch (addr.u.v4.type) { case HOST_TYPE_IPV4: net_addr.s_addr = htonl((uint32_t)addr.u.v4.ip); # ifdef _WIN32 ip_str = inet_ntoa(net_addr); snprintf_p(p, sz, "%s:%hu", ip_str, (uint16_t)addr.u.v4.port); # else inet_ntop(AF_INET, &net_addr, p, sz); ip_len = strlen(p); snprintf_p(p + ip_len, sz - ip_len, ":%hu", (uint16_t)addr.u.v4.port); # endif break; case HOST_TYPE_URI: p = (char*)(uintptr_t)addr.u.uri.uri; break; case HOST_TYPE_GROUP: p = (char*)(((dsn::rpc_group_address*)(uintptr_t)(addr.u.group.group))->name()); break; default: p = (char*)"invalid address"; break; } return (const char*)p; }
/*static*/ mutation_ptr mutation::read_from_log_file(binary_reader& reader, dsn_message_t from) { mutation_ptr mu(new mutation()); unmarshall(reader, mu->data.header, DSF_THRIFT_BINARY); int size; unmarshall(reader, size, DSF_THRIFT_BINARY); mu->data.updates.resize(size); std::vector<int> lengths(size, 0); for (int i = 0; i < size; ++i) { unmarshall(reader, mu->data.updates[i].code, DSF_THRIFT_BINARY); unmarshall(reader, lengths[i], DSF_THRIFT_BINARY); } for (int i = 0; i < size; ++i) { int len = lengths[i]; std::shared_ptr<char> holder(new char[len], [](char* ptr){ delete []ptr; }); reader.read(holder.get(), len); mu->data.updates[i].data.assign(holder, 0, len); } mu->client_requests.resize(mu->data.updates.size()); if (nullptr != from) { mu->_prepare_request = from; dsn_msg_add_ref(from); // released on dctor } snprintf_p(mu->_name, sizeof(mu->_name), "%" PRId32 ".%" PRId32 ".%" PRId64 ".%" PRId64, mu->data.header.pid.get_app_id(), mu->data.header.pid.get_partition_index(), mu->data.header.ballot, mu->data.header.decree); return mu; }