Sequence

MySQL Bug剖析之Slave节点并行复制死锁

让人想犯罪 __ 提交于 2020-12-16 07:14:59
此文已由作者温正湖授权网易云社区发布。 欢迎访问 网易云社区 ,了解更多网易技术产品运营经验。 有天一早,DBA同学就找上来了,说有个DDB集群下的RDS实例Slave节点(从库)死锁了,请求支援。说实话,一大早就遇到死锁这种棘手的问题,我的内心是奔溃的。不过万幸的是,DBA说这个实例还未正式上线,处于上线前压测阶段。这么一来,至少现场可以一直保持着。方便定位问题。那么,是什么问题呢,不卖关子,直接上图: 这是show processlist的结果。可以看到有一大坨的连接,基本上都是权限操作相关的语句,全都卡在“waiting for table level lock”上。还有几个复制管理操作,比如stop slave,也卡住了。这密密麻麻一大堆,看得都烦。还是得从这些连接里面挖掘出少数有用的信息。所以登上实例的mysql客户端捋下才是王道。先看看有没有锁相关的直接信息: show engine innodb status\G ------------ TRANSACTIONS ------------ Trx id counter 6506046 Purge done for trx's n:o < 6506038 undo n:o < 0 state: running but idle History list length 2057 LIST OF TRANSACTIONS

Java基础系列——String的方法(21)

冷暖自知 提交于 2020-12-16 03:25:08
Stirng类的方法有很多,本片博客描述的就是所有的方法,包括一些新的方法(主要是JDK1.8之后新出的方法)。 charAt( int index ) charAt方法描述: Returns the char value at the specified index.返回指定位置的字符 那么也就是说,在方法中传入一个参数,返回一个具体的位置。具体代码如下: public class TestString5 { public static void main(String[] args) { String s = "http://oschina.net/lujiapeng" ; char c = s.charAt( 3 ) ; System.out.println( c ); // p c = s.charAt( 9 ) ; System.out.println( c ); // c c = s.charAt( 100 ) ; System.out.println( c ); // StringIndexOutOfBoundsException: String index out of range: 100 } } 那么在这里清楚的看到,当传入一个3的时候,会返回一个字符p,如果传入一个9的话,会返回一个字符c,如果传入100的话,会抛出一个异常

熬夜整理最全面的HTML字符实体,很下饭

血红的双手。 提交于 2020-12-14 01:13:04
HTML字符实体 HTML字符实体(Character Entities),转义字符串(Escape Sequence) 为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用。这些符号是不显示在我们最终看到的网页里的,那如果我们希望在网页中显示这些符号,该怎么办呢? 这就要说到HTML转义字符串(Escape Sequence)了。 转义字符串 (Escape Sequence)也称字符实体(Character Entity)。在HTML中,定义转义字符串的原因有两个:第一个原因是像“<”和“>”这类符号已经用来表示HTML标签,因此就不能直接当作文本中的符号来使用。为了在HTML文档中使用这些符号,就需要定义它的转义字符串。当解释程序遇到这类字符串时就把它解释为真实的字符。在输入转义字符串时,要严格遵守字母大小写的规则。第二个原因是,有些字符在ASCII字符集中没有定义,因此需要使用转义字符串来表示。 转义字符串的组成 转义字符串(Escape Sequence),即字符实体(Character Entity)分成三部分:第一部分是一个&符号,英文叫ampersand;第二部分是实体(Entity)名字或者是#加上实体(Entity)编号;第三部分是一个分号。 比如,要显示小于号(<),就可以写 < 或者 < 。 用实体

Restful api 防止重复提交

梦想的初衷 提交于 2020-12-12 10:31:13
当前很多网站是前后分离的,前端(android,iso,h5)通过restful API 调用 后端服务器,这就存在一个问题,对于创建操作,比如购买某个商品,如果由于某种原因,手抖,控件bug,网络错误,可能导致一次操作实际上购买了多次同一个产品。所以,我们要考虑防止重复提交。这个重复提交我们只限定于创建操作,对于修改和删除操作,原则上是幂等的,不用担心,查询操作更不用担心重复操作。 方案一,前端在提交时候生成一个基于时间的sequence,将这个参数传到后端,后端根据uriPath+userId+sequence作为key,采用redis分布式锁,setNX,防止重复提交 方案二,前端不用传递sequence,后端根据请求的payload和其他参数来确定唯一,uriPath+userId+MD5(JsonString(所有参数))作为key,用redis分布式锁 具体实现: 对于方案一,防止重复提交交给了前端控制,sequence的生成可以是时间戳。后端可以做在servlet filter 中或者在restful 框架的filter中比如resteasy 的ContainerRequestFilter中 对于第二种方案,防止重复提交完全由后端控制,前端无感,不能做在filter中,因为request payload只能被消费一次。可以用spring aop来实现

leetcode math类型题目解题总结

天大地大妈咪最大 提交于 2020-12-12 10:05:15
2. Add Two Numbers https://leetcode.com/problems/add-two-numbers/description/ class Solution { public : ListNode * addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode result( - 1 ); ListNode * current = & result; int add = 0 ; while (l1!=NULL || l2!= NULL){ int val1 = 0 ; int val2 = 0 ; if (l1!= NULL){ val1 = l1-> val; l1 = l1-> next; } if (l2!= NULL){ val2 = l2-> val; l2 = l2-> next; } current ->next = new ListNode((val1+val2+add)% 10 ); add = (val1+val2+add)/ 10 ; current = current-> next; } if (add == 1 ) current ->next = new ListNode( 1 ); return result.next; } }; View Code 7. Reverse

Moq Sequence with Callback C#

久未见 提交于 2020-12-12 05:12:53
问题 I have this code below with a simple nunit test using Moq Sequence. The unit test works without using Callback, but it fails with Callback. Any ideas? public class MoqDemo { private ISender sender; public MoqDemo(ISender sender) { this.sender = sender; } public void Send() { for (int i = 0; i < 3; i++) { sender.SendMessage(i, $"{i}"); } } } NUnit test [TestFixture] public class MoqDemoTest { [Test] public void SequenceTest() { var sender = new Mock<ISender>(); using (Sequence.Create()) { var

Error while writing fasta file using biopython

梦想的初衷 提交于 2020-12-11 22:02:07
问题 I used the following code to write the fasta sequence into file. from Bio import SeqIO sequences = "KKPPLLRR" # add code here output_handle = open("example.fasta", "w") SeqIO.write(sequences, output_handle, "fasta") output_handle.close() I got the following error: self = <Bio.SeqIO.FastaIO.FastaWriter object at 0x21c1d10>, record = 'M' def write_record(self, record): """Write a single Fasta record to the file.""" assert self._header_written assert not self._footer_written self._record_written

Error while writing fasta file using biopython

不问归期 提交于 2020-12-11 21:59:12
问题 I used the following code to write the fasta sequence into file. from Bio import SeqIO sequences = "KKPPLLRR" # add code here output_handle = open("example.fasta", "w") SeqIO.write(sequences, output_handle, "fasta") output_handle.close() I got the following error: self = <Bio.SeqIO.FastaIO.FastaWriter object at 0x21c1d10>, record = 'M' def write_record(self, record): """Write a single Fasta record to the file.""" assert self._header_written assert not self._footer_written self._record_written

Error while writing fasta file using biopython

独自空忆成欢 提交于 2020-12-11 21:59:05
问题 I used the following code to write the fasta sequence into file. from Bio import SeqIO sequences = "KKPPLLRR" # add code here output_handle = open("example.fasta", "w") SeqIO.write(sequences, output_handle, "fasta") output_handle.close() I got the following error: self = <Bio.SeqIO.FastaIO.FastaWriter object at 0x21c1d10>, record = 'M' def write_record(self, record): """Write a single Fasta record to the file.""" assert self._header_written assert not self._footer_written self._record_written

Muduo网络库源码分析之定时器的实现

南楼画角 提交于 2020-12-07 20:52:37
muduo 的定时器功能由三个 class 实现,TimerId、Timer 和 TimerQueue。 TimerId 类 它唯一标识一个 Timer 定时器。TimerId Class 同时保存Timer* 和 sequence_,这个 sequence_ 是每个 Timer 对象有一个全局递增的序列号 int64_t sequence_,用原子计数器(AtomicInt64)生成。 它主要用于注销定时器,这样就可以区分地址相同的先后两个 Timer 对象。 namespace muduo { namespace net { class Timer; /// /// An opaque identifier, for canceling Timer. /// /* 带有唯一标识的Timer,主要用于取消Timer */ class TimerId : public muduo::copyable { public : TimerId () : timer_ (NULL), sequence_ (0) { } TimerId(Timer* timer, int64_t seq) : timer_(timer), //timer 定时器的指针 sequence_(seq) //seq 该定时任务的序列号 { } // default copy-ctor, dtor and