Watermark picture generation method, device and electronic equipment

By using the first mutex lock mechanism in the distributed system, the problem of low efficiency in watermark image generation is solved, and flexible generation and resource optimization of watermark images are achieved.

CN114064299BActive Publication Date: 2025-11-07UBTECH ROBOTICS CORP LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111277609.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-29
Publication Date
2025-11-07
Estimated Expiration
2041-10-29

AI Technical Summary

Technical Problem

Existing technologies for generating watermarked images are inefficient, leading to resource waste and redundant generation.

Method used

By using a first mutex lock mechanism in the distributed system, it is ensured that only one electronic device can acquire and generate a watermark image at a time. The Zookeeper lock and Redis lock mechanisms are used to avoid duplicate generation and improve generation efficiency.

Benefits of technology

It enables flexible generation of watermarked images, avoids repetitive generation, improves generation efficiency, and optimizes resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114064299B_ABST
    Figure CN114064299B_ABST
Patent Text Reader

Abstract

The application is suitable for the technical field of data processing, and provides a watermark picture generation method and device and electronic equipment, which comprises the following steps: checking whether a watermark picture path indicated by specified information exists in a database; if the watermark picture path indicated by the specified information does not exist in the database, determining a target watermark picture path, wherein the target watermark picture path is determined according to the specified information; taking the target watermark picture path as a first mutual exclusion lock and acquiring the first mutual exclusion lock, wherein the first mutual exclusion lock can be acquired by at most one electronic equipment at the same time, and only after the electronic equipment that has acquired the first mutual exclusion lock releases the first mutual exclusion lock, can other electronic equipment acquire the first mutual exclusion lock; if the first mutual exclusion lock is acquired, generating a watermark picture and storing the target watermark picture path in the database. Through the above method, the watermark picture can be quickly generated.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of data processing, and particularly relates to a watermark picture generation method and device, an electronic device, and a computer readable storage medium. BACKGROUND

[0002] With the development of society, users pay more and more attention to intellectual property. For example, a user can prevent others from using his files by adding a special watermark to the files, thereby effectively protecting the user's personal copyright.

[0003] At present, a terminal usually generates a watermark picture, and then the terminal or another terminal prints the watermark picture on a corresponding file. However, in this method, since the generation of the watermark is completed by a terminal, the generation efficiency of the watermark is low. SUMMARY

[0004] Embodiments of the present application provide a watermark picture generation method and device, an electronic device, and a computer readable storage medium, which can solve the problem of low generation efficiency of a watermark picture.

[0005] In a first aspect, an embodiment of the present application provides a watermark picture generation method applied to an electronic device in a distributed system, and the method comprises the following steps.

[0006] checking whether a watermark picture path indicated by specified information exists in a database;

[0007] If the watermark picture path indicated by the specified information does not exist in the database, determining a target watermark picture path, wherein the target watermark picture path is determined according to the specified information;

[0008] taking the target watermark picture path as a first mutual exclusion lock and acquiring the first mutual exclusion lock, wherein the first mutual exclusion lock can be acquired by at most one electronic device at the same time, and only after an electronic device that has acquired the first mutual exclusion lock releases the first mutual exclusion lock, can other electronic devices acquire the first mutual exclusion lock;

[0009] If the first mutual exclusion lock is acquired, generating a watermark picture and storing the target watermark picture path in the database.

[0010] In a second aspect, an embodiment of the present application provides a watermark picture generation device applied to an electronic device in a distributed system, and the device comprises the following modules.

[0011] A database checking module is configured to check whether a watermark picture path indicated by specified information exists in a database;

[0012] a target watermark picture path determination module configured to determine a target watermark picture path if the watermark picture path indicated by the specified information does not exist in the database, wherein the target watermark picture path is determined according to the specified information;

[0013] a first mutex determination module configured to determine the target watermark picture path as a first mutex and acquire the first mutex, wherein the first mutex can be acquired by at most one electronic device at the same time, and only after the electronic device that has acquired the first mutex releases the first mutex, other electronic devices can acquire the first mutex;

[0014] a watermark picture generation module configured to generate a watermark picture if the first mutex is acquired, and store the target watermark picture path in the database.

[0015] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor implements the method in the first aspect when executing the computer program.

[0016] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the method in the first aspect.

[0017] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on an electronic device, causes the electronic device to perform the method in the first aspect.

[0018] Compared with the prior art, the embodiment of the present application has the following beneficial effects:

[0019] In the embodiment of the present application, since the first mutex can be acquired by at most one electronic device at the same time, and only after the electronic device that has acquired the first mutex releases the first mutex, other electronic devices can acquire the first mutex, therefore, the target watermark picture path is determined as the first mutex, and the electronic device generates the watermark picture only after acquiring the first mutex, which can ensure that only one electronic device can generate the watermark picture, thereby avoiding the repeated generation of the watermark picture. Meanwhile, the target watermark picture path is stored in the database, which is beneficial to the subsequent search of each electronic device in the distributed system. BRIEF DESCRIPTION OF DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description.

[0021] Figure 1 is a flow diagram of a watermark picture generation method provided by an embodiment of the present application;

[0022] Figure 2 is a flow diagram of another watermark picture generation method provided by an embodiment of the present application;

[0023] Figure 3 is a principle diagram of a Zookeeper lock provided by an embodiment of the present application;

[0024] Figure 4 is a structure diagram of a watermark picture generation apparatus provided by an embodiment of the present application;

[0025] Figure 5 is a structure diagram of an electronic device provided by another embodiment of the present application. DETAILED DESCRIPTION

[0026] In the following description, for the purposes of explanation and not limitation, specific details are set forth, such as particular sequences of steps, techniques, etc. in order to provide a thorough understanding of the embodiments of the application. However, it will be apparent to those skilled in the art that the application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known methods, devices, and circuits are omitted so as not to obscure the description of the application with unnecessary detail.

[0027] It should be understood that the term "comprises" when used in this specification and the appended claims, specifies the presence of stated features, integers, steps, operations, elements, and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0028] It should also be understood that the term "and / or" when used in this specification and the appended claims, means any one of the associated listed items can be present or can be absent, and includes the possibility of combinations of one or more of the associated listed items.

[0029] In addition, in the description of the specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish descriptions, and cannot be understood as indicating or implying relative importance.

[0030] Reference within the specification of this application to "one embodiment" or "some embodiments" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the application. The appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in additional embodiments," and so on, in various places in the specification are not necessarily all referring to the same embodiment, nor are they necessarily referring to one or more particular embodiments that are "other" than all the other embodiments. Such phrases are merely devices used herein for convenience and generally do not limit the scope of possible embodiments.

[0031] Example One:

[0032] At present, a watermark picture is usually generated by a terminal, and then the watermark picture is added to a file to be added with a watermark to generate a file with the watermark picture. However, the efficiency of generating the watermark picture by the terminal is low due to the limited processing capability of the terminal.

[0033] To solve the technical problem, the embodiment of the application provides a watermark picture generation method. In the method, a node that acquires a first mutex in a distributed system generates a watermark picture. That is, as long as any node in the distributed system acquires the first mutex, the watermark picture can be generated, thereby improving the flexibility and generation efficiency of the watermark picture. Meanwhile, as the first mutex can be acquired by only one electronic device at the same time, the same watermark picture can be avoided from being repeatedly generated, thereby avoiding the invalid consumption of resources.

[0034] The watermark picture generation method provided by the embodiment of the application is described below in combination with the drawings.

[0035] Figure 1 A flowchart of a watermark picture generation method provided by the embodiment of the application is shown, which is applied to an electronic device in a distributed system, such as a local server, and is described in detail as follows.

[0036] In step S11, whether a watermark picture path indicated by specified information exists in a database is checked.

[0037] In the embodiment, the specified information has a one-to-one correspondence with the watermark picture path, and the unique watermark picture path can be found according to the specified information.

[0038] Specifically, the watermark picture path includes the specified information. The specified information can be issued by a user on the local server or by a user on the electronic device and then forwarded to the local server by the electronic device.

[0039] In some embodiments, considering that a user usually uses his / her name to mark the ownership of a file, the specified information can be set as a user name. Assuming that the user name is "Zhang San", the watermark picture path can be "folder 1 / Zhang San ID / Zhang San", which stores the watermark picture corresponding to the user "Zhang San", and the content of the watermark picture corresponding to the user "Zhang San" is usually "Zhang San".

[0040] In step S12, if the watermark picture path indicated by the specified information does not exist in the database, a target watermark picture path is determined according to the specified information.

[0041] In this embodiment, after it is determined that the watermark picture path indicated by the specified information does not exist in the database, a target watermark picture path is generated according to the specified information. For example, when the specified information is a user name, the target watermark picture path is generated according to the user name and a preset path (which can include a specified disk, or a specified disk and a specified folder, etc.).

[0042] Of course, if the watermark picture path indicated by the specified information exists in the database, the corresponding watermark picture is directly obtained in the watermark picture path. If the corresponding watermark picture is not stored in the watermark picture path, the corresponding watermark picture needs to be generated again.

[0043] In step S13, the target watermark picture path is used as a first mutex and the first mutex is acquired. The first mutex can be acquired by at most one electronic device at the same time, and other electronic devices can acquire the first mutex only after the electronic device that has acquired the first mutex releases the first mutex.

[0044] The first mutex is located on the first cloud server.

[0045] The "other electronic devices" here refer to electronic devices other than the electronic device that has acquired the first mutex.

[0046] In this embodiment, since the first mutex can be acquired by at most one electronic device at the same time, and other electronic devices can acquire the first mutex only after the electronic device that has acquired the first mutex releases the first mutex, it can be ensured that only one electronic device can acquire the target watermark picture path.

[0047] In step S14, if the first mutex is acquired, a watermark picture is generated, and the target watermark picture path is stored in the database.

[0048] In this embodiment, if the content of the watermark picture is the specified information, the watermark picture is generated according to the specified information.

[0049] In the embodiment of the present application, since the first mutex can be acquired by only one electronic device at the same time, and only after the electronic device releases the acquired first mutex, other electronic devices can acquire the first mutex, therefore, the target watermark picture path is taken as the first mutex, and the electronic device generates a watermark picture only after acquiring the first mutex, so that only one electronic device can generate a watermark picture, thereby avoiding repeated generation of watermark pictures. Meanwhile, the target watermark picture path is stored in the database, which is beneficial to subsequent search of each electronic device in the distributed system.

[0050] In order to more clearly describe the watermark picture generation method provided by the embodiment of the present application, an application example is described below:

[0051] Suppose the electronic device is a local server, and a user wants to generate a watermark picture of "Zhang San".

[0052] After the local server acquires the name "Zhang San" input by the user, the local server searches the database to find whether there is a watermark picture path corresponding to "Zhang San", that is, to find a watermark picture path containing "Zhang San".

[0053] If no watermark picture path containing "Zhang San" is found, a target watermark picture path is determined according to "Zhang San", and suppose the determined target watermark picture path is "folder 1 / 123456 / Zhang San", wherein "123456" is the ID of Zhang San and can uniquely point to "Zhang San".

[0054] The "folder 1 / 123456 / Zhang San" is taken as a first mutex and an attempt is made to acquire the first mutex.

[0055] If the first mutex is acquired, a watermark picture with picture content of "Zhang San" is generated, and "folder 1 / 123456 / Zhang San" is stored in the database.

[0056] That is, the user only needs to input "Zhang San", if the database stores a corresponding watermark picture, the local server can find the watermark picture corresponding to "Zhang San", if the database does not store a corresponding watermark picture, the local server can automatically generate the watermark picture corresponding to "Zhang San", and only one local server generates, thereby avoiding multiple servers to generate multiple watermark pictures.

[0057] Example Two:

[0058] Figure 2A flowchart of another method for generating a watermark picture is shown. In this embodiment, steps S24 and S25 are steps for refining step S14 of the first embodiment, and the remaining steps are the same as those of the first embodiment, which will not be described again.

[0059] In step S21, it is checked whether the watermark picture path indicated by the specified information exists in the database.

[0060] In step S22, if the watermark picture path indicated by the specified information does not exist in the database, a target watermark picture path is determined according to the specified information.

[0061] In some embodiments, if the watermark picture path indicated by the specified information exists in the database, it is checked whether the corresponding watermark picture exists under the watermark picture path, and if not, the corresponding watermark picture is generated.

[0062] In step S23, the target watermark picture path is used as a first mutex and the first mutex is acquired, wherein the first mutex can be acquired by at most one electronic device at the same time, and other electronic devices can acquire the first mutex only after the electronic device that has acquired the first mutex releases the first mutex.

[0063] In step S24, if the first mutex is acquired, it is determined whether the watermark picture is created by other distributed nodes.

[0064] Here, the other distributed nodes refer to other electronic devices in the same distributed system as the electronic device.

[0065] In this embodiment, whether the watermark picture is created by other distributed nodes can be determined by the following steps:

[0066] The database is checked again to determine whether the watermark picture path indicated by the specified information exists. If the watermark picture path indicated by the specified information does not exist, or if the watermark picture path indicated by the specified information exists but there is no corresponding watermark picture under the watermark picture path, it is determined that the watermark picture is not created by other distributed nodes, otherwise, it is determined that the watermark picture is created by other distributed nodes.

[0067] In step S25, if the watermark picture is not created by other distributed nodes, the watermark picture is generated and the target watermark picture path is stored in the database.

[0068] In the embodiments of the present application, after the first mutual exclusion lock is acquired, it is determined again whether the watermark picture is created by other distributed nodes, and the watermark picture is generated only when it is confirmed again that the watermark picture is not created by other distributed nodes. Therefore, the probability of repeatedly generating the watermark picture can be further reduced by means of the confirmation again.

[0069] In some embodiments, the first mutual exclusion lock is a Zookeeper lock, and after the corresponding watermark picture is generated, the method further includes:

[0070] releasing the Zookeeper lock.

[0071] The principle diagram of the Zookeeper lock is shown in FIG. 1. Figure 3 The corresponding principle is as follows.

[0072] (1) When the Zookeeper lock is acquired, a temporary sequential node is created under the locker node, and when the Zookeeper lock is released, the temporary sequential node is deleted.

[0073] (2) The client creates a temporary sequential node under the locker by using the createNode method, and then calls getChildren(“locker”) to acquire all the child nodes under the locker, without setting any Watcher (i.e. listener).

[0074] (3) After the client acquires all the child node paths (the path includes the serial number), if it is found that the serial number of the created child node is the smallest, the client acquires the Zookeeper lock.

[0075] (4) If it is found that the serial number of the created temporary sequential node is not the smallest among all the child nodes of the locker, it is indicated that the Zookeeper lock has not been acquired, and the client needs to find a node smaller than itself, and then call the exist() method on the node and register an event listener (Watcher) on the node.

[0076] (5) When the monitored node is deleted, the Watcher of the client receives a corresponding notification, and then the client determines again whether the serial number of the created temporary sequential node is the smallest among all the child nodes of the locker. If yes, the Zookeeper lock is acquired, and if no, the above steps are repeated to acquire a node smaller than itself and register an event listener.

[0077] In the embodiments of the present application, because the Zookeeper lock needs to be released before other electronic devices can acquire the Zookeeper lock and generate the corresponding watermark picture, the Zookeeper lock is released after the watermark picture is generated, which is beneficial to other electronic devices to acquire the Zookeeper lock and generate the corresponding watermark picture.

[0078] In some embodiments, in order to avoid repeated storage, the step of storing the target watermark picture path in the database in the above step S25 (or step S14) comprises:

[0079] A second mutex is added to the target watermark picture path, and the target watermark picture path is stored in the database when the second mutex is successfully added, wherein at most one electronic device can successfully add the second mutex within the same period.

[0080] The second mutex is located on a second cloud server, which can be the same cloud server as the first cloud server or a different cloud server.

[0081] In the embodiments of the present application, if the database does not store the target watermark picture path, the second mutex will be successfully added, otherwise, the second mutex will fail to be added. Because only the electronic device that successfully adds the second mutex can store the target watermark picture path in the database, and at most one electronic device can successfully add the second mutex within the same period, by adding the second mutex to the target watermark picture path, repeated storage of the watermark picture path corresponding to the same target watermark picture in the database can be avoided.

[0082] In some embodiments, the second mutex is a Redis lock, and adding the second mutex to the target watermark picture path comprises:

[0083] An expiration time is set for the target watermark picture path.

[0084] When the expiration time arrives, the second mutex will be invalid. For example, if the expiration time is 5 seconds, the Redis lock will be invalid after 5 seconds.

[0085] The principle of the Redis lock is as follows:

[0086] 1). A attempts to acquire lock information (lockkey), and sets the value (currenttime+timeout) of lockkey to the current time + lock timeout time through the setnx (lockkey, currenttime+timeout) command.

[0087] 2) If the return value is 1, it means that the lockkey does not exist in the Redis server, i.e. no other user has the lock, and A can successfully acquire the lock;

[0088] 3) Since the lockkey is set with an expiration period (i.e. an expiration time) before the business is executed, the deadlock can be prevented. If the expiration period is not set, the lockkey will exist in the Redis server forever, and other users will fail to acquire the lock when executing setnx(lockkey, currenttime+timeout).

[0089] 4) Execute the related business;

[0090] 5) Release the lock. After A completes the related business, A releases the lock, i.e. deletes the lock in the Redis, del(lockkey), and the next user can reset the lock value. It should be noted that since the lockkey is set with an expiration period, the Redis will automatically delete the lock even if A does not release the lock.

[0091] In some embodiments, the first mutual exclusion lock is a Zookeeper lock, and the second mutual exclusion lock is a Redis lock. Since the watermark picture can be generated only after the Zookeeper lock is acquired, and the watermark picture corresponding to a user usually does not change, the Zookeeper lock needs to be released before other electronic devices can acquire this feature, which can avoid frequent execution of the action of generating the watermark picture and will not affect the watermarking of the file to be added with the watermark. At the same time, since the event of storing the watermark picture path to the database occurs frequently, the Redis lock can be used to avoid the deadlock according to the expiration period set by the Redis lock (if the Zookeeper lock is used when the watermark picture path is stored to the database, the Zookeeper lock may be forgotten to be released, and the forgetting to release the Zookeeper lock will cause an exception).

[0092] In some embodiments, before the step S21 (or the step S11) described above, the following steps are included:

[0093] It is checked whether the Redis cache exists the watermark picture path indicated by the specified information.

[0094] Correspondingly, the step S21 (or the step S11) described above includes:

[0095] If the Redis cache does not exist the watermark picture path indicated by the specified information, it is checked whether the database exists the watermark picture path indicated by the specified information.

[0096] In the embodiment of the present application, when the user's watermark picture is generated, the user ID is taken as the key and the corresponding watermark picture path is taken as the value, which are saved in Redis. When saving, the expiration time needs to be set. Since the speed of searching information in the Redis cache is higher than that in the database, when the watermark picture needs to be generated, the corresponding watermark picture path is searched in the Redis cache first, if not, the database is searched, which can improve the searching speed of information.

[0097] In some embodiments, the watermark picture generation method provided by the embodiment of the present application further includes:

[0098] A1, obtaining a file to be added with a watermark.

[0099] In the embodiment, the electronic device can download the file to be added with a watermark in the local or the cloud server. If downloaded from the cloud server, it is verified whether the file exists in the database, if not, the file is downloaded to the local folder and saved to the database; if the file exists in the database, it is queried whether the file exists in the local path, if not, the file is downloaded to the local path.

[0100] It should be pointed out that the above step A1 can be executed before step S11 (or step S21) or after step S14 (or step S25), which is not limited here.

[0101] A2, printing the above watermark picture on the above file to be added with a watermark to obtain a file added with a watermark.

[0102] In the process of printing the watermark picture, the watermark format is also set. The watermark format includes the height, color, transparency and the like of the watermark.

[0103] In the embodiment of the present application, since the watermark picture can be quickly generated, the speed of printing the watermark picture on the file to be added with a watermark can be improved.

[0104] In some embodiments, the generated watermark picture can also be uploaded to a third cloud server. The third cloud server can be the same as the first server (or the second server) or different.

[0105] In some embodiments, the above file added with a watermark is uploaded to the third cloud server, and the local file added with a watermark is deleted to save the local memory.

[0106] In some scenarios, a database query operation is directly performed after Redis expires (lock invalidation), thus, if the expiration time is set too short, the database will be under great pressure in a large concurrency. But if the expiration time is set too long, the Redis memory will be occupied. Therefore, the expiration time of Redis needs to be reasonably set. In some embodiments, the expiration time set for the target watermark picture path can be determined in the following manner:

[0107] B1, estimate the time for generating a watermark picture, and determine the number of files to be added with a watermark.

[0108] B2, determine the above expiration time according to the estimated time and the determined number.

[0109] In this embodiment, it is assumed that the estimated time for generating a watermark picture is 1 second, and the number of files to be added with a watermark is 10, then the expiration time can be set to 11-15 seconds. Since the expiration time takes into account the generation time of the watermark picture and the number of files to be added with a watermark, the determined expiration time is more reasonable.

[0110] It should be understood that the size of the serial number of each step in the above embodiment does not mean the order of execution, and the execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0111] Example Three:

[0112] Corresponding to the above-mentioned watermark picture generation method of the above embodiment, Figure 4 a structural block diagram of a watermark picture generation apparatus provided by an embodiment of the present application is shown, only the part related to the embodiment of the present application is shown for the convenience of description.

[0113] Referring to Figure 4 The watermark picture generation apparatus 4 is applied to an electronic device in a distributed system, and includes a database checking module 41, a target watermark picture path determining module 42, a first mutual exclusion lock determining module 43, and a watermark picture generation module 44. Wherein:

[0114] The database checking module 41 is configured to check whether the watermark picture path indicated by the specified information exists in the database.

[0115] In this embodiment, the specified information has a one-to-one correspondence with the watermark picture path, and the unique watermark picture path can be found according to the specified information.

[0116] Specifically, the watermark picture path includes the specified information, which can be issued by the user on the local server, or issued by the user on the electronic device, and then forwarded to the local server by the electronic device.

[0117] In some embodiments, considering that users usually use their names to mark the ownership of files, the specified information can be set as a user name.

[0118] The target watermark picture path determination module 42 is configured to determine a target watermark picture path if the watermark picture path indicated by the specified information does not exist in the database, and the target watermark picture path is determined according to the specified information.

[0119] In some embodiments, if the watermark picture path indicated by the specified information exists in the database, the corresponding watermark picture is directly obtained in the watermark picture path, and if the corresponding watermark picture is not stored in the watermark picture path, the corresponding watermark picture needs to be regenerated.

[0120] The first mutex lock determination module 43 is configured to determine the target watermark picture path as a first mutex lock and obtain the first mutex lock, where the first mutex lock can be obtained by only one electronic device at the same time, and other electronic devices can obtain the first mutex lock only after the electronic device that has obtained the first mutex lock releases the first mutex lock.

[0121] The watermark picture generation module 44 is configured to generate a watermark picture if the first mutex lock is obtained, and store the target watermark picture path in the database.

[0122] In the embodiments of the present application, since the first mutex lock can be obtained by only one electronic device at the same time, and other electronic devices can obtain the first mutex lock only after the electronic device that has obtained the first mutex lock releases the first mutex lock, the target watermark picture path is determined as the first mutex lock, and the electronic device generates the watermark picture only after obtaining the first mutex lock, so that only one electronic device can generate the watermark picture, thereby avoiding the repeated generation of the watermark picture. Meanwhile, the target watermark picture path is stored in the database, which is beneficial to the search of each electronic device in the subsequent distributed system.

[0123] In some embodiments, the watermark picture generation apparatus 4 further includes:

[0124] The watermark picture existence judgment module is configured to check whether the corresponding watermark picture exists in the watermark picture path if the watermark picture path indicated by the specified information exists in the database, and generate the corresponding watermark picture if not.

[0125] In some embodiments, in the watermark picture generation module 44, if the first mutex lock is obtained, the watermark picture is generated, including:

[0126] If the first mutex is acquired, it is determined whether the watermark picture is created by other distributed nodes. If the watermark picture is not created by other distributed nodes, the watermark picture is generated.

[0127] If the first mutex is acquired, it is determined whether the watermark picture is created by other distributed nodes. If the watermark picture is not created by other distributed nodes, the watermark picture is generated.

[0128] If the first mutex is acquired, it is determined whether the watermark picture is created by other distributed nodes. If the watermark picture is not created by other distributed nodes, the watermark picture is generated.

[0129] In the embodiments of the present application, after the first mutex is acquired, it is determined again whether the watermark picture is created by other distributed nodes. The watermark picture is generated only when it is determined again that the watermark picture is not created by other distributed nodes. Therefore, the probability of generating the watermark picture repeatedly can be further reduced by the determination again.

[0130] In some embodiments, the first mutex is a Zookeeper lock. After the corresponding watermark picture is generated, the method further includes:

[0131] The Zookeeper lock is released.

[0132] In the embodiments of the present application, the Zookeeper lock needs to be released before other electronic devices can acquire the Zookeeper lock and generate the corresponding watermark picture. Therefore, the Zookeeper lock is released after the watermark picture is generated, which is beneficial to other electronic devices to acquire the Zookeeper lock and generate the corresponding watermark picture.

[0133] In some embodiments, the target watermark picture path is stored in the database in the watermark picture generation module 44, including:

[0134] A second mutex is added to the target watermark picture path. When the second mutex is added successfully, the target watermark picture path is stored in the database. In the same period, only one electronic device can add the second mutex successfully.

[0135] In the embodiment of the present application, if the database does not store the target watermark picture path, the second mutex will be added successfully, otherwise, the second mutex will be added unsuccessfully. Since only the electronic device that successfully adds the second mutex can store the target watermark picture path in the database, and at most only one electronic device can successfully add the second mutex in the same period, by adding the second mutex for the target watermark picture path, repeated storage of the watermark picture path corresponding to the same target watermark picture in the database can be avoided.

[0136] In some embodiments, the second mutex is a Redis lock, and adding the second mutex for the target watermark picture path includes:

[0137] setting an expiration time for the target watermark picture path.

[0138] In some embodiments, the watermark picture generation apparatus 4 includes:

[0139] a cache searching module configured to search whether the Redis cache stores the watermark picture path indicated by the specified information.

[0140] Correspondingly, the database checking module 41 is specifically configured to:

[0141] if the Redis cache does not store the watermark picture path indicated by the specified information, check whether the database stores the watermark picture path indicated by the specified information.

[0142] In some embodiments, the watermark picture generation apparatus 4 further includes:

[0143] a file to be added with a watermark obtaining module configured to obtain a file to be added with a watermark.

[0144] In the embodiment, the electronic device can download the file to be added with a watermark in the local or the cloud server. If the file is downloaded from the cloud server, it is first verified whether the file already exists in the database. If not, the file is downloaded to the local folder and saved to the database. If the file exists in the database, it is queried whether the file exists in the local path. If not, the file is downloaded to the local path.

[0145] a watermark printing module configured to print the watermark picture on the file to be added with a watermark to obtain a file added with a watermark.

[0146] In the process of printing the watermark picture, a watermark format is further set. The watermark format includes the height, color, transparency and the like of the watermark.

[0147] In some embodiments, the generated watermarked image may also be uploaded to a third cloud server, which may be the same as or different from the first server (or the second server).

[0148] In some embodiments, the watermarked files are uploaded to a third-party cloud server, and the watermarked files are deleted locally to save local memory.

[0149] In some scenarios, considering that database queries will be performed immediately after Redis expires (lock expires), setting the expiration time too short will put significant pressure on the database under high concurrency. However, setting the expiration time too long will consume Redis memory. Therefore, it is necessary to set the Redis expiration time appropriately. In some embodiments, the expiration time set for the target watermark image path can be determined in the following ways:

[0150] Estimate the time required to generate the watermarked image, and determine the number of files to be watermarked; determine the expiration time based on the estimated time and the determined number.

[0151] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.

[0152] Example Four:

[0153] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 5 As shown, the electronic device 5 of this embodiment includes: at least one processor 50 ( Figure 5 The diagram shows only one processor, memory 51, and computer program 52 stored in the memory 51 and executable on at least one processor 50. When the processor 50 executes the computer program 52, it implements the steps in any of the above method embodiments.

[0154] The aforementioned electronic device 5 can be a computing device such as a server. This electronic device may include, but is not limited to, a processor 50 and a memory 51. Those skilled in the art will understand that... Figure 5 This is merely an example of electronic device 5 and does not constitute a limitation on electronic device 5. It may include more or fewer components than shown, or combine certain components, or different components, such as input / output devices, network access devices, etc.

[0155] The processor 50 can be a central processing unit (CPU), and can also be other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.

[0156] The memory 51 can be an internal storage unit of the electronic device 5, such as a hard disk or a memory of the electronic device 5 in some embodiments. The memory 51 can also be an external storage device of the electronic device 5, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 5 in other embodiments. Further, the memory 51 can include both the internal storage unit and the external storage device of the electronic device 5. The memory 51 is used to store an operating system, an application program, a boot loader, data, and other programs, such as program codes of the computer program, etc. The memory 51 can also be used to temporarily store data that has been output or will be output.

[0157] It can be clearly understood by those skilled in the art that, for the convenience and brevity of description, only the division of the above functional units and modules is taken as an example, and in actual application, the above functions can be completed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to complete all or part of the above-described functions. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can exist physically independently, or two or more units can be integrated in one unit, and the integrated unit can be realized in the form of hardware or in the form of a software functional unit. In addition, the specific names of the functional units and modules are only for the convenience of mutual distinction, and do not limit the protection scope of the present application. The specific working process of the units and modules in the system can refer to the corresponding process in the foregoing method embodiments, which will not be described here.

[0158] The embodiment of the present application further provides a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program is executed by a processor to realize the steps in the various method embodiments.

[0159] The embodiment of the present application provides a computer program product, when the computer program product is run on an electronic device, the electronic device is caused to execute to realize the steps in the various method embodiments.

[0160] The integrated units described above can be stored in a computer readable storage medium if they are realized in the form of software function units and sold or used as independent products. Based on such understanding, the present application realizes all or part of the processes in the above-mentioned embodiment methods, which can be completed by a computer program instructing related hardware. The computer program described above can be stored in a computer readable storage medium, and the computer program can realize the steps in the various method embodiments when executed by a processor. The computer program includes computer program code, which can be in the form of source code, object code, executable files or some intermediate forms. The computer readable medium at least includes any entity or device capable of carrying the computer program code to the photographing device / electronic device, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium. For example, U disk, mobile hard disk, magnetic disk or optical disk, etc. In some jurisdictions, according to legislation and patent practice, the computer readable medium cannot be an electrical carrier signal and a telecommunication signal.

[0161] In the above embodiments, the description of each embodiment has its own focus, and the parts not described or recorded in detail in a certain embodiment can be referred to the relevant description of other embodiments.

[0162] Those skilled in the art can realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0163] In the embodiments provided by the present application, it should be understood that the disclosed apparatus / network device and method can be implemented in other manners. For example, the embodiments of the apparatus / network device described above are merely schematic, and the division of the modules or units is merely logical function division, and there can be another division manner in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between the units can be indirect couplings or communication connections through some interfaces, devices or units, and can be electrical, mechanical or in other forms.

[0164] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.

[0165] The above embodiments are merely used to describe the technical solutions of the present application, rather than limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalent; and these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A method of generating a watermarked picture, characterized by, An electronic device applied to a distributed system, comprising: acquiring user inputted specified information, checking whether a watermark picture path indicated by the specified information exists in a database, the specified information having a one-to-one correspondence with the watermark picture path, and a unique watermark picture path being able to be found according to the specified information; if the watermark picture path indicated by the specified information does not exist in the database, determining a target watermark picture path, the target watermark picture path being determined according to the specified information; taking the target watermark picture path as a first mutual exclusion lock and acquiring the first mutual exclusion lock, wherein the first mutual exclusion lock can be acquired by at most one electronic device at the same time, and other electronic devices can acquire the first mutual exclusion lock only after the electronic device that has acquired the first mutual exclusion lock releases the first mutual exclusion lock; if the first mutual exclusion lock is acquired, generating a watermark picture and storing the target watermark picture path in the database, the target watermark picture path being used to store the watermark picture.

2. The watermark picture generating method of claim 1, characterized by, The if the first mutual exclusion lock is acquired, generating a watermark picture, comprises: if the first mutual exclusion lock is acquired, judging whether the watermark picture is created by other distributed nodes; if not created by other distributed nodes, generating the watermark picture.

3. The method of claim 1, wherein The first mutual exclusion lock is a Zookeeper lock, and after the watermark picture is generated, the method further comprises: releasing the Zookeeper lock.

4. The method of claim 1, wherein The storing the target watermark picture path in the database, comprises: adding a second mutual exclusion lock to the target watermark picture path, and storing the target watermark picture path in the database when the adding of the second mutual exclusion lock is successful, wherein at most one electronic device can successfully add the second mutual exclusion lock at the same time.

5. The method of claim 4, wherein the watermark image is generated by: The second mutual exclusion lock is a Redis lock, and the adding of the second mutual exclusion lock to the target watermark picture path comprises: setting an expiration time for the target watermark picture path.

6. The method of claim 5, wherein the watermark image is generated by: Before the checking whether the watermark picture path indicated by the specified information exists in the database, the method further comprises: checking whether the watermark picture path indicated by the specified information exists in a Redis cache; The checking whether the watermark picture path indicated by the specified information exists in the database, comprises: if the watermark picture path indicated by the specified information does not exist in the Redis cache, checking whether the watermark picture path indicated by the specified information exists in the database.

7. The method of generating a watermarked picture according to any one of claims 1 to 6, characterized in that, The method further comprises: acquiring a file to which a watermark is to be added; printing the watermark picture on the file to which the watermark is to be added to obtain a file to which a watermark is added.

8. A watermark picture generating apparatus characterized by comprising: An electronic device applied to a distributed system, comprising: a database checking module configured to acquire user inputted specified information, check whether a watermark picture path indicated by the specified information exists in a database, the specified information having a one-to-one correspondence with the watermark picture path, and a unique watermark picture path being able to be found according to the specified information; The target watermark picture path determination module is configured to determine a target watermark picture path if the watermark picture path indicated by the specified information does not exist in the database, and the target watermark picture path is determined according to the specified information. The first mutex determination module is configured to determine the target watermark picture path as a first mutex and acquire the first mutex, wherein the first mutex can be acquired by at most one electronic device at the same time, and only after the electronic device that has acquired the first mutex releases the first mutex, other electronic devices can acquire the first mutex. The watermark picture generation module is configured to generate a watermark picture if the first mutex is acquired, and store the target watermark picture path in the database, wherein the target watermark picture path is used to store the watermark picture.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor executes the computer program to implement the method in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 9. The computer program is executed by the processor to implement the method in any one of claims 1 to 7.

Citation Information

Patent Citations

  • File processing method and device

    CN106776720A

  • Distributed document generation method and device, computer equipment and readable storage medium

    CN110321541A

  • Method and system for adding picture watermark to browser client

    CN111583091A