segment

ConcurrentHashMap源码详解

我怕爱的太早我们不能终老 提交于 2019-11-29 01:16:44
1. ConcurrentHashMap概述 ConcurrentHashMap是线程安全的哈希表,不同于HashTable,后者在方法上增加synchronized关键字,利用对象同步锁实现线程之间的同步。显然,HashTable实现线程安全的方式太“重”,并发度高的情况下,很多线程争用同一把锁,吞吐量较低。 ConcurrentHashMap通过锁分段技术,只有在同一个段内,才会存在锁竞争,提高了并发处理能力。它的内部数据结构其实是一个Segment数组,该数组的大小代表了ConcurrentHashMap的并发度,Segment同时也是一把可重入锁,该锁用来确保该段数据并发访问的线程安全。每一个Segment其实是一个类似于HashMap的哈希表,用来存储key-value。看下ConcurrentHashMap结构图: ConcurrentHashMap维护了一个Segment数组segments,每个Segment是一个哈希表。当线程需要访问segments[1]处的哈希表,首先需要获取该段的锁,然后才能访问该段的哈希表。上图中segments数组大小为8,因此并发度为8,最多支持8个线程在不同的段同时访问。 2. HashEntry HashEntry代表了哈希表的一个key-value项,它是ConcurrentHashMap的一个内部静态类

GreenPlum 最佳实践

江枫思渺然 提交于 2019-11-28 23:04:07
数据模型 Greenplum数据库是一种shared nothing的分析型MPP数据库。这种模型与高度规范化的/事务型的SMP数据库有显著区别。Greenplum数据库使用非规范化的模式设计会工作得最好,非规范化的模式适合于MPP分析型处理,例如带有大型事实表和较小维度表的星形模式或者雪花模式。 对表中用于连接的列使用相同的数据类型。 堆存储 vs. 追加优化存储 对将会接收迭代批量或者单一UPDATE、DELETE以及INSERT操作的表和分区使用堆存储。 对将会接收并发UPDATE、DELETE以及INSERT操作的表和分区使用堆存储。 对于在初始装载后很少更新并且只会在大型批处理操作中进行后续插入的表和分区,使用追加优化存储。 绝不在追加优化表上执行单个INSERT、UPDATE或者DELETE操作。 绝不在追加优化表上执行并发的批量UPDATE或DELETE操作。可以执行并发的批量INSERT操作。 行存 vs. 列存 如果负载中有要求更新并且频繁执行插入的迭代事务,则对这种负载使用行存。 在对宽表选择时使用行存。 为一般目的或混合负载使用行存。 选择面很窄(很少的列)和在少量列上计算数据聚集时使用列存。 如果表中有单个列定期被更新而不修改行中的其他列,则对这种表使用列存。 压缩 在大型追加优化和分区表上使用压缩以改进系统范围的I/O。 在数据位于的级别上设置列压缩设置。

undo日志

徘徊边缘 提交于 2019-11-28 21:40:26
undo日志 作用 因一些原因(机器宕机/操作系统错误/用户主动rollback等)导致事务执行到一半,但这时事务的执行已经让很多信息修改了(提交前就会边执行边修改记录),但还有部分未执行,为了保证事务的一致性与原子性,要么全都执行成功,要么全都失败,所以就需要回滚,而rollback需要旧值依据,而这些旧值记录就存储在undo日志中。 redo日志记录 记录时机 InnoDB存储引擎在实际的进行增删改操作时,每操作一条记录都会先把对应的undo日志记录下来。 undo日志通用结构 undo日志存储在类型为FIL_PAGE_UNDO_LOGO的页面中,而每条记录添加到数据页中时,都会隐式的生成两个列trix_id和roll_pointer,trix_id就是事务id,roll_pointer是指向记录对应的undo日志的一个指针 end of record:本条undo日志在页中结束地址 undo type:undo日志类型 undo no:undo日志编号,事务没提交时,每生成一条undo日志就递增1 table id:本条undo 日志对应记录所在table id(information_schema库中表innodb_sys_tables查看) 主键各列信息列表:<len, value>关键列占用空间和真实值信息列表 start of record:本条undo

What's the right way to define an anchor tag in rails?

放肆的年华 提交于 2019-11-28 20:37:39
It's obvious from the documentation (and google) how to generate a link with a segment e.g. podcast/5#comments . You just pass a value for :anchor to link_to . My concern is about the much simpler task of generating the <a name="comments">Comments</a> tag i.e. the destination of the first link. I've tried the following, and although they seemed to work, the markup was not what I expected: link_to "Comments", :name => "comments" link_to "Comments", :anchor => "comments" I think I'm missing something obvious. Thanks. You are getting confused by Ruby's syntactic sugar (which Rails uses profusely)

Greenplum failed segment的恢复方法--primary与mirror都可修复

前提是你 提交于 2019-11-28 18:04:14
  当在使用greenplum过程中有不当的操作时,可能会出现segment节点宕掉的情况(比如在greenplum运行的过程中停掉其中几台segment节点的服务器),通过下面的方法可以恢复segment。 下面是现场出现的故障情况: [gpadmin@tj-soc-c04-csfb1 ~]$ gpstate -m 20161010:16:35:54:026100 gpstate:tj-soc-c04-csfb1:gpadmin-[INFO]:-Starting gpstate with args: -m 20161010:16:35:55:026100 gpstate:tj-soc-c04-csfb1:gpadmin-[INFO]:-local Greenplum Version: 'postgres (Greenplum Database) 4.3.6.2 build 1' 20161010:16:35:55:026100 gpstate:tj-soc-c04-csfb1:gpadmin-[INFO]:-master Greenplum Version: 'PostgreSQL 8.2.15 (Greenplum Database 4.3.6.2 build 1) on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4

Segment Tree

可紊 提交于 2019-11-28 17:34:15
Leetcode上一道题,给定一个整数数组,要实现: 求[i, j]所有元素的和,0 <= i <= j <= n - 1,sumRange(i, j) 数组的元素会被修改, update(i, val) 这两个函数会被均匀的调用很多次 最简单的方法是求和O(n),修改元素O(1),时间复杂度太大,使用Segment Tree可以将二者的时间复杂度均变为O(logn) Segment Tree: 叶子节点是输入数组中的所有元素 内部节点是其孩子节点所带信息的merge Segment Tree可以由数组实现,数组索引i的左孩子为2 * i + 1,右孩子为2 * i + 2,父节点在(i - 1) / 2下取整处 该数组的大小为$2 * 2 ^(ceil(log_2^n)) - 1$ 来源: https://www.cnblogs.com/betaa/p/11416493.html

What's the real meaning of $$ in nasm

☆樱花仙子☆ 提交于 2019-11-28 14:16:46
$$ is defined as current segment address in NASM. But what's the real meaning of it? I wrote two asm files to test it: a.asm extern another [section .text] global _start _start: mov ebx, $$ call another b.asm [section .text] global another another: mov eax, $$ ret compile nasm -f elf a.asm -g nasm -f elf b.asm -g ld -o test a.o b.o Using gdb to debug the final file test , I found that though I defined two sections with the same name, the $$ is different in both file. So I guess that: Once I defined a section in a file, the value of $$ is the starting address of that section. And $$ has nothing

ArraySegment - Returning the actual segment C#

╄→尐↘猪︶ㄣ 提交于 2019-11-28 09:53:27
I have been looking around on ways to return the segment which is basically held by ArraySegment in terms of offset and count. Although ArraySegment holds the complete and original array, it just delimits it with the fact that any changes to the segment are reflected into the original. The problem or say the limitation with ArraySegment is that it will not return the segment itself as a whole and I have to traverse the values. What would be the best way to return the segment as a whole? byte[] input = new byte[5]{1,2,3,4,5}; ArraySegment<byte> delimited = new ArraySegment<byte>(input,0,2);

HashMap和ConcurrentHashMap的区别

余生颓废 提交于 2019-11-28 07:44:50
为了线程安全,ConcurrentHashMap 引入了一个 “分段锁” 的概念。具体可以理解把一个大的 map 拆分成 N 个小的 Map 。最后再根据 key.hashcode( )来决定放到哪一个 hashmap 中去。 hashmap 本质是数组+链表,根据 key.hashcode( ) 计算出数组对应下标。如果多个 key 对应同一个下标,用一个链表串起来,新数据在前面。 ConcurrentHashMap :在 hashmap 基础上,ConcurrentHashMap 将数据分解成多个 segment (默认 16 个),每次操作对 segment 加锁,避免多线程锁的几率,提高并发效率。 来源: https://my.oschina.net/u/3973793/blog/3096629

Glass Carving CodeForces - 527C (线段树)

天涯浪子 提交于 2019-11-28 01:15:43
C. Glass Carving time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm  ×  h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular