![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Database
文章平均质量分 52
Database related
Tech In Pieces
这个作者很懒,什么都没留下…
展开
-
什么是分布式缓存?原理是什么?
在微服务架构中,分布式是一定需要的。因为我们的服务器是分布式集群,数据库是集群。这回给我们的缓存带来挑战。那么这个时候 我们的缓存也必须要是分布式的吗?还是说也可以只用一个cache server?先不考虑那么多 先考虑一定用分布式缓存。分布式缓存有两种:一种是一JBoss cache为代表的互相通信同步的分布式缓存。他是每台服务器上都部署app和cache。另一种是以memcache为代表的互相不通信的分布式缓存。缓存与应用分离部署,缓存系统部署在一组专门的服务器上,应用程序通过一致性Hash原创 2021-12-28 05:35:38 · 1780 阅读 · 1 评论 -
Redis的两种持久化机制:RDB和AOF
RDB是定时的持久机制(snap–快照机制)。也就是说会在固定的时间段(或者空闲时间段)才做数据统一。所以如果有宕机的情况,那么就会出现数据丢失。AOF是基于日志的持久机制。应用缓存介绍Redis持久化机制:RDB和AOF...原创 2021-12-28 05:34:19 · 320 阅读 · 0 评论 -
分布式系统下使用缓存可能存在的问题及解决方法
缓存击穿。就是有一些缓存在被超高并发访问前恰好失效。导致大量请求涌入数据库。【解决方法 给数据库加锁(用synchronized或者用分布式锁【redis给我们实现好了】) 同一时间只有一个请求去查 然后这个查询结果会被缓存 然后后续请求发现这个请求被缓存了】缓存穿透。故意大量去查询一些不存在的数据。然后因为缓存没有击中 数据库也没有,所以也不会被写道缓存中。然后如果重复请求 那么每次都要从数据库去读。会导致系统负载过大。[解决方法:将查询到的null也写入缓存,并设置较为短暂的过期时间]缓存雪崩:指.原创 2021-12-28 05:31:59 · 356 阅读 · 0 评论 -
什么是分布式锁?为什么用分布式锁?有哪些常见的分布式锁?
我们为什么需要分布式锁?因为我们的数据库或者是app的server通常有很多个,而我们高并发请求的时候,只用一个锁肯定不行了(比如只加synchronized关键字)所以 面对微服务架构下的并发请求。我们需要分布式锁。【就是说 多个数据库+多个并发的请求,使得我们需要分布式锁。如果只是一个数据库+多个并发请求,只需要用synchronized或者reentrantLock就行了。并发请求才是我们用锁的关键原因。如果没有并发 我们根本用不到锁】常见的分布式锁:基于数据库的分布式锁悲观锁乐观锁【ve原创 2021-12-28 05:29:04 · 2184 阅读 · 0 评论 -
Redis到底是数据库还是缓存?
缓存也是一种数据库。不过因为其体量比较小,可以放在内存中,所以检索速度非常快。就算不在内存中,因为其储存高频查询结果和小体量,因此检索速度也非常快。因为缓存的本质也是信息条目的储存和取用。所以 比较精确的说法是,Redis是缓存数据库。...原创 2021-12-28 05:24:07 · 1001 阅读 · 0 评论 -
数据库操作隔离级别(isolation level)详解
四个隔离级别:未提交读(read uncommitted)提交读(read committed)重复读(repeatabe read)序列化(seriaizabe)通过一些现象 可以反映隔离级别效果。更新丢失(ost update):当系统允许两个事务同时更新同一数据是,发生更新丢失。脏读(dirty read):当一个事务读取另一个事务尚未提交的修改时,产生脏读。非 重复读(nonrepeatabe read):同一查询在同一事务中多次进行,由于其他提交事务所做的修改或删除,每次返回不同的原创 2021-12-28 05:23:44 · 976 阅读 · 0 评论 -
面试向:SpringData MongoDB
还是那一套:加spring data mongoDB 的dependencies 在Pom.xml里面。然后config mongoDB by add the configration class:@Configurationpublic class AppConfig { public @Bean MongoClient mongoClient() { return MongoClients.create('mongodb://localhost:27017'); }}what’原创 2021-12-20 05:50:36 · 140 阅读 · 0 评论 -
How to decouple Relational Databases in Microservice architecture?
Chapter 4. Decomposing the Databasecontinuing use the shared databased. (many be some concurrent problem)continuing use the shared databased but access it with a proxy called entitlements services.3. database as a service interface.Pattern: Shared d原创 2021-12-20 05:48:46 · 110 阅读 · 0 评论 -
面试向:How to do distributed transactions in MongoDB 4.2?
Distributed transactions, which extend multi-document ACID guarantees from replica sets to sharded clusters, give customers an easier way to address a complete range of use cases by enforcing transactional guarantees across highly scaled, global applicatio原创 2021-12-20 05:44:51 · 105 阅读 · 0 评论 -
什么是分布式事务(Distributed transactions)?
first of all, what’s transaction?it a set of SQL statements that follows ACID principles.ACID is the principle of transaction, like SQL.atomiticity: do it or don;t do at allconsistency: data needs to be concurrent after we did the transactionisolation原创 2021-12-18 05:57:38 · 419 阅读 · 0 评论 -
面试向:How to config database/databases in microservices?
why do we need to config different databases in micro services?Because all the microservices are loose coupled with each other. so that means when one microservice change something in db, it won’t infect to other microservices.但是我们又不能将DB完全分开 为什么呢?因为这样会造成原创 2021-12-18 05:56:40 · 75 阅读 · 0 评论 -
Hibernate链接和JDBC链接数据库有什么区别?
Hibernate先检索缓存中的映射对象(即操作对象)而JDBC则是直接操作数据库。Hibernate的底层其实还是JDBC。 所以 如果我们正确的使用JDBC 效率是要比hibernate好的,但是因为我们更适合去操作Object 更符合Java“万物皆对象”的思想。...原创 2021-12-18 05:56:08 · 94 阅读 · 0 评论 -
什么是NAT Server?
首先 这些事干什么用的?private network, use public ip address to provide service for external users.nat server功能使得内部服务器可以供外部网络访问。外部网络的用户访问内部服务器时,nat将请求报文的目的地址转换成内部服务器的私有地址。对内部服务器回应报文而言,nat还会自动将回应报文的源地址(私网地址)转换成公网地址。nat server是什么?解决内网问题的nat穿透方法有哪些?...原创 2021-12-17 05:31:06 · 3197 阅读 · 0 评论 -
为什么微服务架构中每个微服务要用独立的数据库?
之前的项目:因为都是MySQL数据库 所以有的时候我们需要join查表 但是如果每个service都有自己数据库 那么这些跨数据库的交流 会变得及其低效。但是 我们的microserviice架构,其实本质上是想把services 给loosely decoupling.所以 不只是services要被decoupling. 数据也要分开。因为这个低耦合的事情 不只是service低耦合 而且数据库层面 也需要低耦合。因为数据库如果只用一个 其实微服务之间的耦合也没有降低。并且 之前的情况是所有的都用一原创 2021-12-17 05:28:08 · 4435 阅读 · 0 评论 -
面试知识点大总结:Core Java+DB+Advanced Java
Core Java:java 8 new featuresOptional: used for handling nullPointExceptiondefaultOOPwhat is thread pool and the adv of itdaemon thread?heaps vs stack in JVMhow GC works and can we force it?how to make thread safe? based on those ways choose what?原创 2021-12-16 05:34:57 · 157 阅读 · 0 评论 -
SQL/NoSQL:面试前的扫盲
NoSQL and SQL:what is NoSQL?Stands for non relational database. the data stored in NoSQL database is diversity, like k-v pair, document, graph format.What’s the advantage and disadvantages of NoSQL?adv: support for unstructured text. and support for mu原创 2021-12-11 05:32:02 · 393 阅读 · 0 评论 -
面试概念总结之九--ORM
这个绕不过 兄弟 还是老老实实的总结一下。三件套:what is ORM? what’s the adv? what’s the principle?ORM: object relational mapping. it coverts between the data in relational DB to an object which will be used in OOD.it often goes with Hibernate(which is a java based persisten原创 2021-10-14 05:14:09 · 125 阅读 · 0 评论 -
面试向:如何利用Amazon RDS来管理微服务架构中的数据库?
它是一种托管服务。可以简化我们设置 操作和拓展数据库的过程。数据库实例:就是一个在云上的数据库环境,可以通过AWS RDS API 或者是AWS CLI.然后就可以启动这个实例。如何访问运行中的数据库实例:通过AWS管理控制台。RDS可以运行多个数据库实例?40.每个数据库实例中可以运行多少个数据库或者数据库架构?for most of rd, not limited.for oracle, 一个数据库 但是结构可以有多个。在用RDS之前 我们要将我们自己的数据库里面的数据和配置导入到R原创 2021-12-08 05:38:59 · 151 阅读 · 0 评论 -
面试向:数据库事务和Stored Procedure的区别
Before this, I do know that transaction means a group of SQL statements to do something.and so is stored procedure.here’s the difference:A transaction is a logical unit of work that contains one or more SQL statements.A transaction ends when it is comm原创 2021-12-07 05:48:28 · 533 阅读 · 0 评论 -
面试向:什么是分布式事务以及如何实现
首先我们知道数据库事务 他遵守着ACID(Atom, Consistency, isolation, durability)他是从四个不同的维度来描述事物的特性:原子性 —— 事务操作的整体性–success or rollback一致性 —— 事务操作下数据的正确性–隔离性 —— 事务并发操作下数据的正确性–transactions are independent持久性 —— 事务对数据修改的可靠性-committed data is never lost分布式数据库事务:对于ACID是个挑原创 2021-12-07 05:35:31 · 202 阅读 · 0 评论 -
事务,分布式事务和关系型,非关系型数据库的关系
我们知道 关系型数据库遵守 ACID非关系型数据库遵守CAP-BASE疑问:为什么只有关系型数据库提供事务处理支持?如果我们想在微服务架构中对非关系型数据库进行分布式事务操作怎么办?首先要明确的一点就是:因为NoSQL的高拓展性(horizontal scaling)一旦我们要做事务操作 就一定是分布式的。但是 NoSQL不支持事务/分布式事务、为什么?因为nosql一般都是强调扩展性的,这就是数据会有很多分区,分布在不同的机器上,要支持事务就得实现分布式事务,实现低延迟的分布式事务是一个原创 2021-12-07 05:34:50 · 1397 阅读 · 0 评论 -
深入思考ACID,CAP,BASE理论
Relational database has transaction, ACID are the rules for transaction.CAP is mainly for distributed system, means that any distributed system can only satisfy 2 out of 3, it has a close relationship with NoSQL because many of the Non-relational database原创 2021-12-07 05:30:56 · 395 阅读 · 0 评论 -
究竟什么是数据库索引?一句话
Indexing is a data structure that store all the values of a column, and whenever it’s necessary, we can search s specific value very fastthat’s why we are using B+ tree to do the indexing in MySQL原创 2020-10-29 10:15:13 · 107 阅读 · 0 评论 -
什么是死锁?(Dead lock) 如何解决死锁问题?
different process requests for the same resource and they both wait others to make a move first.死锁发生需要有什么条件?互斥,就是在一段时间内某一资源自能由一个进程占有请求和保持,就是说在当前进程已经占有资源的情况下,还在请求其他已经被其他进程占有的资源,就是既不得不到想要的,也不愿意放开已经拥有的。不剥夺 就是说进程已经获得资源 自能由自己释放 其他人夺不走环路等待 意思是死锁发生的时候 必然存在一原创 2020-11-02 01:43:56 · 703 阅读 · 0 评论 -
Transaction in Database? ACID. 什么是数据库事务?
A transaction symbolizes a unit of work performed within a database management system, and it is independent with other transactions but they are coherent and reliable. So in short, it represents any changes in the database.It has four properties: ACIDAt原创 2020-10-28 07:40:13 · 171 阅读 · 0 评论 -
SQL Join, Inner Join, Outer Join, Left join
Join == inner join, it selects records that have matching value in both tables.Outer join equals to full join: it returns all the records when there is match in left and right table records.Left join returns all the records from the left table and the ma原创 2020-10-28 07:35:16 · 58 阅读 · 0 评论