0%

Lucene简介

lucene是apache旗下的一款高性能、可伸缩的开源的信息检索库,elasticsearch和sorl都是基于Lucene来实现的

概念

lucene中几个重要的概念

索引库Index

lucene中一个目录就是一个索引库,同一个文件夹下的所有文件构成一个索引库,一个索引是多个Document的集合

段Segment

Lucene索引可能由多个子索引组成,这些子索引称为段,每一段都是独立的索引,段与段之间是相互独立的。当添加一个新文档就会生成一个新的段,并且也会触发段文件合并,段文件中记录了索引中包含有多少个段,每个段包含有多少个文档

在Lucene中段是不可变的,只可读,不可写,此时对于不同的操作来说

  • 增:有新数据需要创建索引时,由于段的不变性,会新建一个段来存储新增的数据
  • 删:当删除数据时,由于段不可写,会在Lucene中新增一个.del文件,用来专门存储被删除的id。在查询时,被删除的数据还是可以被查到的,只有进行文档链表合并时,才会把删除的数据过滤掉(删除的数据在段合并的时候才会被真正移除)
  • 改:修改操作其实就是删除+新增,先在.del文件中标记旧数据的删除,再在新段中添加一条更新后的数据

Lucene采用延迟写的方式,新增的数据会先写入内存,然后批量写到磁盘。若有一个段被写到磁盘,就会生成一个提交点,来记录所有提交后的段信息的文件。一个段一旦拥有了提交点,这个段就只可读不可写了,而段在内存中时,是只有写权限没有读权限的

延迟写可以减少磁盘写入次数,提升性能,降低磁盘压力

文档Document

文档(document),在lucene的定义中,文档是一系列域(field)的组合,而文档的域则代表一系列与文档相关的内容,与数据库表的记录的概念有点类似,一行记录所包含的字段对应的就是文档的域,举例来说,一个文档比如老师的个人信息,可能包括年龄、身高、性别、个人简介等等

阅读全文 »

final关键字

final可以用来修饰变量、方法和类

final方法

final方法的作用是防止子类通过重写改变方法的行为
类中所有的private方法都是隐式的指定为final,因为不能访问private方法,所以不能重写它。给private方法加上final修饰并不会给方法带来额外的含义。重写一个private方法时编译并不会报错,一个方法是private的,他就不属于父类的一部分,只是创建了一个同名的方法而已

final方法的好处

  • 可以防止子类中的方法重写
  • final方法会告诉编译器对于final方法的调用不需要动态绑定,在运行时,不需要进行解析方法调用
  • 能够带来更好的效率,编译器对final方法的调用为内联调用。当编译器看到final方法调用时,可以根据自己的判断,略去一般通过方法调用机制插入代码的方式。调用机制包括将方法参数压栈、清除栈参数和最后处理返回值。而对于final方法编译器在方法体中使用实际代码来替换方法调用

final类

final类的作用是该类不允许被继承

final变量

使用final关键字修饰的变量会被认为是常量,final修饰的成员变量必须要进行初始化,任何在程序中试图改变常量值的操作,都会导致编译错误

CSS简单使用

overflow:hidden 防止字溢出

list-style:none 可以出去列表前的.

块状元素和行内元素

块状元素

块状元素特点

  • 每个块状元素都会从新的一行开始,会自动换行
  • 块级元素可以包含行内元素和其他块级元素
  • 高度、宽度、行高、顶部、底部边距都可设置
  • 宽度在不设置的情况下与父元素宽度一致
1
<div><p><h1>...<h6><ol><ul><dl><table><address><blockquote><form>

可以通过设置display:block将元素显示为块状元素

行内元素

行内元素特点

  • 和其他元素在一行上,不会自动换行
  • 一般行内元素只能包含内容或者其他行内元素
  • 高度、宽度、顶部和底部边距都不可设置
  • 元素的宽度是所包含内容的宽度,不可改变
1
<a><span><br><i><em><strong><label><q><code>

可以通过设置display:inline将元素显示为行内元素

行内块状元素

行内块状元素特点

  • 和其他元素在一行上
  • 高度、宽度、行高、顶部、底部边距都可设置
1
<img><input>

可以通过设置display:inline-block将元素显示为行内块状元素

打开新窗口

1
2
3
4
5
6
7
<!-- url地址,窗口名称,参数字符串
name可以选择 top 框架网页中在上部窗口中显示目标网页
self 在当前窗口显示目标网页
black 在新窗口中显示目标网页

-->
window.open(url,name,args)

kafka配置文件

kafka中有很多的配置文件,如server.properties、zookeeper.properties等,下面就一一讲解一下配置文件中的配置

server.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
############################# Server Basics #############################

# broker的全局唯一编号,不能重复
broker.id=0

#删除topic功能使能,如果为false,则无法删除topic
delete.topic.enable=true

############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092

# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured. Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

#处理网络请求的线程数量
num.network.threads=3

# 用来处理磁盘IO的线程数量
num.io.threads=8

# 发送套接字的缓冲区大小
socket.send.buffer.bytes=102400

# 接收套接字的缓冲区大小
socket.receive.buffer.bytes=102400

# 请求套接字的缓冲区大小
socket.request.max.bytes=104857600


############################# Log Basics #############################

# kafka运行日志存放的路径
log.dirs=/tmp/kafka-logs

# 默认分区数
num.partitions=1

# 用来恢复和清理data下数据的线程数量
num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended for to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
# 1. Durability: Unflushed data may be lost if you are not using replication.
# 2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
# 3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to excessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# segment文件保留的最长时间,超时将被删除,默认是7天
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

# log文件最大的大小,如果超过会创建一个新的文件
# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

############################# Zookeeper #############################

# 配置连接Zookeeper集群地址
zookeeper.connect=localhost:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000


############################# Group Coordinator Settings #############################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.
group.initial.rebalance.delay.ms=0